I'm doing documentation for a project. On the website everything is showing correctly in the preview, though it is showing error "Resolver error Cannot read property '0' of undefined".
When generating client in html2 response schema is blank.
UPDATE: showing full code now.
I've tried cutting one level (Entity->EntityItem->EntityResponse to Entity->EntityResponse), error stopped, HTML still not showing full data.
openapi: 3.0.0
info:
description: not working
version: "1.0.0"
title: ...
contact:
email: work#pls.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
#====================================================================================
paths:
/search/nip/{nip}:
get:
operationId: nip?date
parameters:
- in: path
name: nip
required: true
schema:
type: string
minLength: 10
maxLength: 10
description: "Nip"
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityResponse'
'400':
description: ...
description: ...
/search/regon/{regon}:
get:
operationId: regon?date
parameters:
- in: path
name: regon
required: true
schema:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: ...
example: '364760520'
description: Regon
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityResponse'
'400':
description: ...
description: ...
/search/bank-account/{bank-account}:
get:
operationId: bank-account?date
parameters:
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: ...
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityListResponse'
'400':
description: ...
description: ...
/check/nip/{nip}/bank-account/{bank-account}:
get:
operationId: checkNip
parameters:
- in: path
name: nip
required: true
schema:
type: string
minLength: 10
maxLength: 10
description: "Nip"
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: Numer rachunku bankowego
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityCheckResponse'
'400':
description: ...
description: ...
/check/regon/{regon}/bank-account/{bank-account}:
get:
operationId: checkRegon
parameters:
- in: path
name: regon
required: true
schema:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: numer identyfikacyjny REGON
example: '364760520'
description: Regon
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: ...
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityCheckResponse'
'400':
description: ...
description: ...
#====================================================================================
components:
schemas:
EntityRequestBase:
properties:
data:
type: string
format: date
example: '2019-05-17'
bank-account:
type: array
items:
type: string
minLength: 26
maxLength: 26
example: '90249000050247256316596736'
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
regon:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: |
...
example: '364760520'
pesel:
type: string
description: |
...
minLength: 11
maxLength: 11
example: '22222222222'
required:
- data
#====================================================================================
Exception:
properties:
message:
type: string
example: 'error message'
code:
type: integer
required:
- message
- code
#====================================================================================
Person:
properties:
firstName:
type: string
example: Jan
lastName:
type: string
example: Nowak
pesel:
$ref: '#/components/schemas/EntityRequestBase/properties/pesel'
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
#====================================================================================
EntityPerson:
allOf:
- $ref: '#/components/schemas/Person'
- properties:
companyName:
type: string
example: 'Nazwa firmy'
#====================================================================================
EntityCheck:
properties:
accountAssigned:
type: string
example: TAK
description: |
...
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
Entity:
allOf:
- properties:
name:
type: string
example: 'ABC Jan Nowak'
description: |
...
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
statusVat:
type: string
enum:
- C
- Z
- P
example: Z
description: |
...
regon:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: |
...
example: '364760520'
pesel:
$ref: '#/components/schemas/EntityRequestBase/properties/pesel'
krs:
type: string
example: '0000636771'
maxLength: 10
minLength: 10
description: |
...
residenceAddress:
type: string
example: 'ul/ Taka a Owaka 12 01- Warszawa'
description: |
...
workingAddress:
type: string
representatives:
type: array
items:
$ref: '#/components/schemas/Person'
description: |
...
authorizedClerks:
type: array
items:
$ref: '#/components/schemas/Person'
description: |
...
partners:
type: array
items:
$ref: '#/components/schemas/EntityPerson'
description: |
...
registrationLegalDate:
type: string
format: date
example: '2018-02-21'
registrationDenialDate:
type: string
format: date
example: '2019-02-21'
description: |
...
registrationDenialBasis:
type: string
example: 'Ustawa o podatku od towarów i usług art. 96'
description: |
...
restorationDate:
type: string
format: date
example: '2019-02-21'
description: |
...
restorationBasis:
type: string
example: 'Ustawa o podatku od towarów i usług art. 96'
description: |
...
accountNumbers:
type: array
items:
type: string
minLength: 26
maxLength: 26
example: '90249000050247256316596736'
hasVirtualAccounts:
type: boolean
example: true
description: |
...
required:
- name
#====================================================================================
EntityItem:
allOf:
- properties:
subject:
$ref: '#/components/schemas/Entity'
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
EntityList:
allOf:
- properties:
subjects:
type: array
items:
$ref: '#/components/schemas/Entity'
description: |
...
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
EntityResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityItem'
EntityCheckResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityCheck'
EntityListResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityList'
The issue seems to be caused by the ? question mark in operation IDs:
operationId: nip?date
If you remove the question mark, HTML2 docs will include response schemas.
You can file a bug report in the Swagger Codegen repository at https://github.com/swagger-api/swagger-codegen/issues.
Found the solution, it was due to the misuse of "allOf", without them error stops and HTML is generated correctly. It only made sense in "Person", all the other cases were deleted.
Related
I need to develop a Mule API ( 4.4 Runtime ) with openapi: 3.0.0
The endpoint is a POST with the following request payload :
{
"Employee": {
"Address": {
"City": "a",
"Country": "aaa"
}
}
}
Here is the relevant section of the OpenAPI 3.0 spec :
openapi: "3.0.0"
paths:
/search:
post:
tags:
- SearchUser
summary: Search for Users
operationId: getUser
requestBody:
description: User Request Object
content:
application/json:
schema:
$ref: '#/components/schemas/RequestComp'
required: true
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ResponseComp'
'400':
description: Bad request
content: {}
'404':
description: User not found
content: {}
'405':
description: Validation exception
content: {}
components:
schemas:
RequestComp:
type: object
properties:
Employee:
$ref: '#/components/schemas/EmployeeComp'
EmployeeComp:
type: object
properties:
Address:
$ref: '#/components/schemas/AddressComp'
AddressComp:
type: object
properties:
City:
type: string
required: true
nullable: false
minLength: 1
Country:
type: string
required: true
nullable: false
minLength: 1
ResponseComp:
type: object
properties:
City:
type: string
Country:
type: string
So I can validate individual elements like 'City' and 'Country' to not be null but how do I prevent following request ? ( presently its not being flagged as invalid : )
{
"Address": {
"City": "a",
"Country": "aaa"
}
}
You can define the Employee wrapper as a required property and also disallow unknown properties by adding additionalProperties: false. Note that required is not a property-level attribute, but an object-level attribute - it's a list of required properties.
components:
schemas:
RequestComp:
type: object
required: [Employee] # <-----
properties:
Employee:
$ref: '#/components/schemas/EmployeeComp'
additionalProperties: false # <-----
EmployeeComp:
type: object
properties:
Address:
$ref: '#/components/schemas/AddressComp'
additionalProperties: false # <-----
AddressComp:
type: object
required: [City, Country] # <-----
properties:
City:
type: string
# required: true # <-- remove this
nullable: false
minLength: 1
Country:
type: string
# required: true # <-- remove this
nullable: false
minLength: 1
additionalProperties: false # <-----
We are trying to validate a json in APIM 3.1.0 by defining the validation conditions in swagger definition and by enabling the schema validation under runtime configurations. PFA the Swagger definition.
When additional fields are passed in the request json apart from the fields defined in the swagger, the validation must fail or gateway should ignore those additional fields and shouldn't be passing it to the backend. But this is not happening currently, Could you please suggest us if we are missing anything here.
Sample Request JSON
Note : In this JSON, "test" field is an additional parameter sent in the request.
{
"applicationId": "Test123_3211",
"name": "Bala krishna",
"dateOfBirth": "1981-04-11",
"gender": "FEMALE",
"phonenumber": "9039283630",
"altphonenumber": "9979979971",
"panCard": "AAAAV1234N",
"nomineeName": "Ramji Ambedkar",
"nomineeDOB": "1976-04-14",
"source": "ONLINE",
"process": "Canara HSBC",
"callDate": "2018-08-24",
"callTime": "17:00",
"merType": "VIDEOMER",
"instantCall": true,
"test": "abcd"
}
Below is the swagger API :
swagger: "2.0"
info:
version: v1.0.0
title: MedicalBookAppointmentAPI
description: "This API is for booking medical appointments. \n\nSupported operations :\n\n\t1. Docs APP "
schemes:
https
http
produces:
application/json
paths:
/docs-app:
post:
summary: This API will be used to add cases and to schedule appointments.
description: This API will be used to add cases and to schedule appointments.
parameters:
- in: body
name: Payload
description: Request Body
required: true
schema:
$ref: "#/definitions/docs-app-request"
responses:
"200":
description: OK
schema:
$ref: "#/definitions/docs-app-response"
"400":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: Bad Request. Invalid request or validation error.
"415":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: " Unsupported Media Type. The entity of the request was in a not supported format."
"500":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: Internal Server Error
produces:
- application/json
consumes:
- application/json
x-auth-type: "Application & Application User"
x-throttling-tier: Unlimited
definitions:
docs-app-request:
type: "object"
required:
- "applicationId"
- "process"
properties:
applicationId:
type: "string"
name:
type: "string"
dateOfBirth:
type: "string"
pattern: "^\d{4}-\d{2}-\d{2}$"
gender:
type: "string"
phonenumber:
type: "number"
altphonenumber:
type: "number"
panCard:
type: "string"
nomineeName:
type: "string"
nomineeDOB:
type: "string"
pattern: "^\d{4}-\d{2}-\d{2}$"
source:
type: "string"
process:
type: "string"
planDetails:
type: "string"
priorityStatus:
type: "string"
callDate:
type: "string"
pattern: "^\d{4}-\d{2}-\d{2}$"
callTime:
type: "string"
metaInfo:
type: "string"
instantCall:
type: "boolean"
merType:
type: "string"
enum:
- "TELEMER"
- "VIDEOMER"
- "OTHERS"
docs-app-response:
type: object
properties:
data:
type: object
properties:
approved:
type: boolean
isInternational:
type: boolean
id:
format: int64
type: integer
applicationId:
type: string
name:
type: string
dateOfBirth:
type: string
gender:
type: string
phonenumber:
type: string
altphonenumber:
type: string
panCard:
type: string
nomineeName:
type: string
nomineeDOB:
type: string
merType:
type: string
vendor:
type: string
updatedAt:
type: string
createdAt:
type: string
success:
type: integer
book-appointment-api-error:
title: Error object returned with HTTP status
type: object
properties:
fault:
type: object
properties:
code:
format: int64
type: integer
type:
type: string
message:
description: Error message.
type: string
description:
description: A detail description about the error message.
type: string
required:
- code
- message
You can use either additionalProperties or minProperties/maxProperties in the swagger file and restrict the additional properties in the payload.
If you know the property count to be limited then use minProperties/maxProperties
If you don't know the property count to be limited then use additionalProperties
For more details please refer https://m-saranki.medium.com/unboxing-json-schema-validator-320-2dd944dae6c0
It's weird for Mongoose to say that because I'm pretty sure I have the thing.
This is my Mongoose model:
var Job = mongoose.model('Job', new Schema({
_creator: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
companyName: {
type: String,
required: true,
trim: true
},
position: {
type: String,
required: true,
trim: true
},
isCurrent: {
type: Boolean
// required: true
},
startedDate: {
type: Date,
required: true
},
endDate: {
type: Date
},
descriptions: [{
description: {
type: String,
required: true
},
skills: [{
skillId: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
skillName: {
type: String,
required: true
}
}]
}]
}));
And here's the dummy data I'm trying to send to my server, printed right before posting:
Yet it tells me that it requires the path description which is already included in the job object above:
Super confused. Any help appreciated!
Hey guys I'm trying to create OAS3 200 response which returns JSON inside of JSON. The problem is I simply don't know what syntax I should use here. I tried to make a double reference but I don't know if it's possible to do that way.
{
"success": false,
"messageType": "error",
"error": {
"apiKey": "apiKey must not be empty"
}
}
responses:
'200':
description: Upon successful generated invoice you will be returned with the following JSON.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/success'
- $ref: '#/components/schemas/invalid'
components:
schemas:
invalid:
type: object
properties:
success:
description: Says if the invoice was generated successfully.
type: boolean
example: false
messageType:
description: Type of the message
type: string
example: error
error:
schema:
$ref: '#/def/data'
def:
data:
type: object
properties:
apikey:
description: lol
type: string
example: lolol
You are almost there. Define your data schema in components/schemas, and make the error property a $ref to this schema.
components:
schemas:
invalid:
type: object
properties:
success:
...
messageType:
...
error:
$ref: '#/components/schemas/data' # <--------
data: # <--------
type: object
properties:
apikey:
description: lol
type: string
example: lolol
Another way is to define the nested schema inline:
components:
schemas:
invalid:
type: object
properties:
success:
...
messageType:
...
error:
type: object # <--------
properties:
apikey:
description: lol
type: string
example: lolol
I am having a problem in defining the array of objects in swagger yaml. Swagger editor is giving an error everytime I try to define the type: array part of the yaml. I defined it, but it is not right as it is giving an error.
Following is the json I am trying to define in swagger yaml.
{
"CountryCombo": {
"options": {
"option": [{
"id": "GB",
"value": "GB Great Britain"
}, {
"id": "US",
"value": "US United States"
}, {
"id": "AD",
"value": "AD Andorra, Principality of"
}]
}
}
}
I defined this json into swagger yaml like this but it is giving an error:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
description: GB
value:
type: string
description: GB Great Britain
- id:
type: string
description: US
value:
type: string
description: US United States
- id:
type: string
description: AD
value:
type: string
description: AD Andorra, Principality of
Can anyone suggest me how would I define this json in yaml following swagger specifications?
In a schema, you don't want to have the values, only the description of the values.
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
type: object
properties:
id:
type: string
value:
type: string
The above answer is also right but I already implemented this in my yaml. I found that I can also define array by creating another definition.
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
$ref: '#/definitions/Country_row'
Country_row:
type: object
properties:
id:
type: string
value:
type: string
The accepted answer cannot achieve the output desired the question. Swagger documentation on examples explains how to add multiple examples for an array of objects:
definitions:
ArrayOfCatalogItems:
type: array
items:
$ref: '#/definitions/CatalogItem'
example:
- id: 38
title: T-shirt
- id: 114
title: Phone
OP was actually on the right track, but made a syntactic mistake:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
example:
- id: GB
value: GB Great Britain
- id: US
value: US United States
- id: AD
value: AD Andorra, Principles of