I've already done the coding and the API response is something like the following:
"response": {
"meta": [ .. this is an array that contains arrays of objects
[
{}
]
]
"javascript": [
{
"attribute": "type",
"value": "applicaion/ld+json"
},
{
"@context": "http://schema.org",
"@graph": {
"organization": {
"@type": "Organization",
"additionalType": "Organization",
"@id": "https://www.example.com/home",
"name": " Example name",
"sameAs": [
"https://twitter.com",
"https://www.facebook.com/",
"https://www.instagram.com/",
"https://www.linkedin.com/company/company/",
"https://en.wikipedia.org/wiki/_Group"
],
"telephone": "083135",
"contactPoint": {
"@type": "ContactPoint",
"telephone": "083135",
"areaServed": {
"@type": "Country",
"name": "Example name"
}
},
"logo": {
"@type": "ImageObject",
"representativeOfPage": "True",
"url": "https://example.com/sites/default/files/_logo_4.svg"
}
}
}
}
]
}
However, I need to write the YML for this endpoint, and I have done so using swagger openapi: 3.0.0.
With attention to the javascript key, the response looks something like this:
pageResponse:
allOf:
- required:
- pageAlias
properties:
statusCode:
type: string
example: 200
statusMessage:
type: string
example: OK
supportMessage:
type: string
example: Content returned
response:
type: object
properties:
content:
type: object
allOf:
- $ref: "#/components/schemas/mainContent"
meta:
type: array
items:
allOf:
- $ref: "#/components/schemas/metaAttribute"
javascript:
type: array
items:
anyOf:
- $ref: "#/components/schemas/javaScriptAttribute"
- $ref: "#/components/schemas/javaScriptSchema"
Question: Is there a way I can define the two objects inside the javascript key without using anyOf? The reason for this is because both objects must always exist. It is not optional.
I hope that the question is well phrased.
Your use of
allOfis not necessary for most of your schemas.allOfis mostly used when combining multiple schemas into a larger schema or to work around the limitation of OpenAPI 3.x.x allowing siblings to a$refwhere you may want a uniquedescriptionortitlefor a property.e.g.
regarding your
javascriptarray. if you put the references into an array ofitems, it will act like a tuple and validate the array instance to have these two schemas as index 0 and 1 for each instance of thejavascriptarray.regarding your comment about
meta.. array of array of objects, I updated your schema to handle that.FYI, this schema will always fail because you have a
required: pageAliasbut it's not apart of this schema.