-
Notifications
You must be signed in to change notification settings - Fork 53
Improve JSON Schema output from the parser #562
Comments
QQ: Should we also handle and transform all type expressions and give a simple to read and consistent output? I know that parsing things like |
@KonstantinSviridov can you guys investigate if there are other nodes that can be expressed differently like: type: Dog[] type: array
items: Dog mediaType: application/json mediaType: [ application / json ] I am sure there are others. |
Others are types:
test:
type: object
properties:
name: string
example:
value: !include examples/actionsRead.json types:
test:
type: object
properties:
name: string
example: !include examples/actionsRead.json |
I'd also suggest to introduce a {
"type": {
"mediaType": "application/raml+yaml",
"content": {
"type": "array",
"items": "Dog"
}
}
} Given the mediaType, I know exactly how to parse the content. Might be helpful and its just an idea. Would love to see what others think. |
Why would we put actual type definition into the "content" field. May be lets just introduce an additional "mediaType" field: "types": {
"Account": {
"name": "Account",
"displayName": "Account",
"mediaType": "application/xml",
"type": [
"<xs:schema attributeFormDefault=\"unqualified\" elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n <xs:element name=\"TwilioResponse\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"Account\">\n <xs:complexType>\n <xs:sequence>\n <xs:element type=\"xs:string\" name=\"Sid\"/>\n <xs:element type=\"xs:string\" name=\"FriendlyName\"/>\n <xs:element type=\"xs:string\" name=\"Type\"/>\n <xs:element type=\"xs:string\" name=\"Status\"/>\n <xs:element type=\"xs:string\" name=\"DateCreated\"/>\n <xs:element type=\"xs:string\" name=\"DateUpdated\"/>\n <xs:element type=\"xs:string\" name=\"AuthToken\"/>\n <xs:element type=\"xs:string\" name=\"Uri\"/>\n <xs:element name=\"SubresourceUris\">\n <xs:complexType>\n <xs:sequence>\n <xs:element type=\"xs:string\" name=\"AvailablePhoneNumbers\"/>\n <xs:element type=\"xs:string\" name=\"Calls\"/>\n <xs:element type=\"xs:string\" name=\"Conferences\"/>\n <xs:element type=\"xs:string\" name=\"IncomingPhoneNumbers\"/>\n <xs:element type=\"xs:string\" name=\"Notifications\"/>\n <xs:element type=\"xs:string\" name=\"OutgoingCallerIds\"/>\n <xs:element type=\"xs:string\" name=\"Recordings\"/>\n <xs:element type=\"xs:string\" name=\"Sandbox\"/>\n <xs:element type=\"xs:string\" name=\"SMSMessages\"/>\n <xs:element type=\"xs:string\" name=\"Transcriptions\"/>\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n</xs:schema>"
]
},
"SomeType": {
"name": "SomeType",
"displayName": "SomeType",
"mediaType": "application/raml+yaml",
"type": [
"object"
],
"properties": {
"name": {
"name": "name",
"displayName": "name",
"type": [
"string"
]
}
},
"examples": [
{
"value": "{\n \"name\": \"somestring\"\n}",
"strict": true,
"name": null,
"structuredValue": {
"name": "somestring"
}
}
]
}
}, |
Looks ok for me too :) BTW, looking at your example: "examples": [
{
"value": "{\n \"name\": \"somestring\"\n}",
"strict": true,
"name": null,
"structuredValue": {
"name": "somestring"
}
}
] Whats the difference between |
As for exmaple, everything is going to be fine, because we're going to serialize an erray of ExampleSpec objects which look exactly the same disregarding whether one uses example:
value: !include examples/actionsRead.json or example: !include examples/actionsRead.json |
I've realized that we can not use maps for
Thus, we have to use arrays here. |
|
As for {
"type" : "array",
"items": {
"oneOf": [
{ "type": "string", "description": "type name or schema content (for external types)" },
{ "ref": "#path/to/TypeDeclaration/definition" },
{ "ref": "#path/to/ObjectTypeDeclaration/definition" },
{ "ref": "#path/to/UnionTypeDeclaration/definition" },
etc
]
}
} Thus, in case of an inline type types:
T1:
type:
properties:
p1: we'll have "types": [
{
"T1": {
"type": [
{
"type": [
"object"
],
"properties": {
"p1": {
"type": [
"string"
]
}
}
}
]
}
}
] At the same time, "type": [
"Cow",
{
"type": "union",
"components": [ "Cat", "Dog" ]
}
] , where |
With regards to the string |
With regards to union. We actually already have a certain format for that raml-org/raml-spec#541. We just haven't had much time to merge it yet, but the output could already follow that model. So type: union
anyOf: [ Cat, Dog ] |
Ok, it seems that we do not need a separate field for string value. Lets remove As for union types format, lets use
we will have
|
Note that |
@sichvoge
will be
|
The listed changes are implemented in #570 |
Thanks @KonstantinSviridov. Can you please add what we discussed about |
@sichvoge Thanks for reminding about Actually, I've already implemented type expressions resolving. Should I remove it? |
becomes |
Yes please remove it again. Only the items that has been put into the OP (first comment) has been agreed on. |
I guess this one can be closed. Please reopen if there are still matters to discuss. |
We've got a lot of very good feedback about the current JSON object that comes back from the parser. Most predominantly, the output should be more consistent.
This issue describes the different changes we'd like to make. Please feel free to help and discuss in this matter.
Improvements
mediaType
string
or anarray
array
types
array
of single key objectsmap
traits
array
of single key objectsmap
resourceTypes
array
of single key objectsmap
annotationTypes
array
of single key objectsmap
securitySchemes
array
of single key objectsmap
schemas
schemas
keytypes
keyschema
schema
keytype
keyexample
example
keyexamples
keyvalue
(ExampleSpec)string
,object
,array
, 'number',boolean
ornull
New
completeRelativeUri
string
string
value.parentUrl
string
string
value.allUriParameters
array
array
.allUriParameters
array
allUriParameters
value of the owning resource. Adding it to any method as an optionalarray
.mediaType
(for Type)string
application/json
orapplication/xml
for external types andapplication/raml+yaml
for the restRemove
structuredExample
structuredValue
(ExampleSpec)The text was updated successfully, but these errors were encountered: