should NOT have additional properties - swagger

I am new to Open API specification ( ia m using 3.0). I am playing with swagger Editor online tool and I am getting a weird error of:
"should NOT have additional properties
additionalProperty: Data1, Data2"
Here is sample of YAML file I am working with:
paths:
/api/assignment:
post:
tags:
- Assignment
summary: "Endpoint to create Resources in system"
description: "This endpoint will create blah blah"
operationId: CreateResource
parameters:
- name: assignment
in: body
description: "This is an object to be sent"
required: true
schema:
type: object
properties:
Ganesh:
type: integer
Test:
type: string
RefClaim:
Data1:
FirstName:
type: string
LastName:
type: string
Data2:
FirstName2:
type: string
LastName2:
type: string
I have seen all questions asked and tried with those but I could not get answer.
Note: I am using Open Api specification 3.0.1

There are a few issues:
1) in: body parameters are an OpenAPI 2.0 thing. OpenAPI 3.0 uses requestBody instead.
2) Nested objects also need the type: object and properties keywords.
The correct version is:
paths:
/api/assignment:
post:
tags:
- Assignment
summary: "Endpoint to create Resources in system"
description: "This endpoint will create blah blah"
operationId: CreateResource
requestBody: # <-----------
required: true
content:
application/json:
schema:
type: object
properties:
Ganesh:
type: integer
Test:
type: string
RefClaim:
type: object # <-----------
properties: # <-----------
Data1:
type: object # <-----------
properties: # <-----------
FirstName:
type: string
LastName:
type: string
Data2:
type: object # <-----------
properties: # <-----------
FirstName2:
type: string
LastName2:
type: string

Related

Swagger 2.0 - Structural error at definitions.testPOST should NOT have additional properties

I am trying to add an array in my swagger 2.0 but I keep getting the following error:
Structural error at definitions.testPOST
should NOT have additional properties
additionalProperty: testRequests
I've checked the swagger documentation but I don't know what I am doing wrong. I could delete 'testRequests' but I need it.
The code is as follows:
swagger: '2.0'
info:
version: v1
title: testAPI
security:
- default: []
paths:
/testPOST:
post:
summary: test
description: test
parameters:
- in: body
name: Payload
description: test
required: true
schema:
$ref: '#/definitions/testPOST'
responses:
'201':
description: Success
schema:
type: object
properties:
status:
type: string
description: HTTP statuscode
title:
type: string
description: Success
detail:
type: string
description: Empty
'401':
description: No access
schema:
type: object
properties:
status:
type: string
description: HTTP statuscode
title:
type: string
description: Message invalid
detail:
type: string
description: Error message
'500':
description: Server error
security:
- default:
- testRequest
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
x-wso2-application-security:
security-types:
- oauth2
optional: false
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
securityDefinitions:
default:
type: oauth2
authorizationUrl: 'https://test.com'
flow: implicit
scopes:
testRequest: Scope
x-scopes-bindings:
testRequest: 'testRequest,admin'
definitions:
testPOST:
testRequests:
type: array
items:
type: object
properties:
sourceUrl:
type: string
example: 'http://example.com/test/1202112'
description: The reference url.
default: 'null'
inboundReferenceNumber:
type: string
example: '1234567890'
description: The request identifier.
default: 'null'
Can somebody please point out what I am doing wrong? Thanks in advance!
If the request body is supposed to be just an array of objects
[
{"sourceUrl": ...},
{"sourceUrl": ...},
...
]
then the definition should be:
definitions:
testPOST: # Remove the "testRequests:" line from here
type: array
items:
..
If the request body is supposed to be an object with the testRequests property whose value is an array
{
"testRequests": [
{"sourceUrl": ...},
{"sourceUrl": ...},
...
]
}
then the definition should be:
definitions:
testPOST:
type: object
properties:
testRequests:
type: array
items:
type: object
properties:
sourceUrl:
...
inboundReferenceNumber:
...

How to require form parameters on the value of another form parameter in OpenAPI?

I have the following OpenAPI (Swagger) definition for a POST request with form data. How can I vary the required form parameters based on the value of the type parameter?
If type="email" only the email is required and if type="phone" only country and phone parameters are required.
/login:
post:
required:
- type
- password
responses:
200:
description: Successful response
schema:
$ref: '#/definitions/SomeResponse'
parameters:
- name: type
type: string
in: formData
enum: [email, phone]
- name: email
type: string
in: formData
- name: country
type: string
in: formData
- name: phone
type: string
in: formData
- name: password
type: string
Conditional dependencies in form data can be expressed in OpenAPI 3, but not in OpenAPI 2.0 (swagger: 2.0).
OpenAPI 3.1
This example uses if..then, a new construct in OAS 3.1.
openapi: 3.1.0
...
paths:
/login:
post:
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/LoginRequest'
responses:
'200':
description: Successful response
components:
schemas:
LoginRequest:
type: object
required:
- type
- password
properties:
type:
type: string
enum: [email, phone]
email:
type: string
country:
type: string
phone:
type: string
password:
type: string
# Conditional dependencies
allOf:
# If type="email", then the `email` field is required
- if:
properties:
type:
const: email
then:
required: [email]
# If type="phone", then the `country` and `phone` fields are required
- if:
properties:
type:
const: phone
then:
required: [country, phone]
OpenAPI 3.0.x
In OAS 3.0, you can use the following oneOf construct to express these conditions.
openapi: 3.0.3
...
paths:
/login: ... # The path definition is the same as in the previous example
components:
schemas:
LoginRequest:
type: object
required:
- type
- password
properties:
type:
type: string
enum: [email, phone]
email:
type: string
country:
type: string
phone:
type: string
password:
type: string
# Conditional dependencies
oneOf:
# If type="email" ...
- properties:
type:
enum: [email]
# ... then the `email` field is required
required: [email]
# If type="phone" ...
- properties:
type:
enum: [phone]
# ...then the `country` and `phone` fields are required
required: [country, phone]
OpenAPI 2.0
In OpenAPI 2.0, the most you can do is define the conditionally required parameters (email, country and phone in your example) as optional and mention the dependencies in the operation description and/or parameter descriptions.
swagger: '2.0'
...
paths:
/login:
post:
...
parameters:
- name: type
type: string
in: formData
enum: [email, phone]
required: true
- name: email
type: string
in: formData
description: Required if type=email
- name: country
type: string
in: formData
description: Required if type=phone
- name: phone
type: string
in: formData
description: Required if type=phone
- name: password
type: string
in: formData
required: true

"TypeError: Failed to fetch" when making a GET request from SwaggerHub

I have the following API definition in SwaggerHub:
swagger: '2.0'
info:
description: defaultDescription
version: '0.1'
title: defaultTitle
host: swapi.co
paths:
/api/people:
get:
produces:
- application/json
parameters:
- name: search
in: query
required: false
type: string
x-example: luke
responses:
'200':
description: Definition generated from Swagger Inspector
schema:
$ref: '#/definitions/Model0'
responseSchema:
$ref: '#/definitions/Model0'
definitions:
Results:
properties:
name:
type: string
height:
type: string
mass:
type: string
hair_color:
type: string
skin_color:
type: string
eye_color:
type: string
birth_year:
type: string
gender:
type: string
homeworld:
type: string
films:
type: array
items:
type: string
species:
type: array
items:
type: string
vehicles:
type: array
items:
type: string
starships:
type: array
items:
type: string
created:
type: string
edited:
type: string
url:
type: string
Model0:
properties:
count:
type: integer
format: int32
next:
type: object
previous:
type: object
results:
type: array
items:
$ref: '#/definitions/Results'
I cannot make this basic GET command to bring back the data I'm seeking. It only returns this:
TypeError: Failed to fetch
I'm unsure if it's a syntax issue, or possibly spacing, but I'm also getting an error for line 19 that reads:
should NOT have additional properties
additionalProperty: responseSchema, description, schema
Any ideas what is wrong?
https://swapi.co seems to be HTTPS-only, so you need to add
schemes:
- https
to you API definition to specify the protocol for requests.
but I'm also getting an error for line 19 that reads: "should NOT have additional properties additionalProperty: responseSchema, description, schema".
Remove these lines:
responseSchema:
$ref: '#/definitions/Model0'
There's no responseSchema keyword in OpenAPI.

Swagger says"not a valid parameter defenition"

I'm fairly new to swagger and would appreciate some direction on good resources for learning.
I have a test project that I'm putting together and I am running into some issues.
I'm getting an error saying that the "parameters" in my "delete" block is not valid. It looks ok to me from what I've seen in the examples. But apparently I'm missing something. Any ideas?
swagger: "2.0"
info:
version: "2"
title: My Title
description: Provides services for vacation rentals site
termsOfService: Private
contact:
name: My Name
url: www.myurl.com
email: my#email.address
license:
name: MIT
url: http://opensource.org/licenses/MIT
schemes:
- http
host: myurl.com
basePath: /api
paths:
/guestbook:
get:
summary: Gets some persons
description: Returns a list containing all persons.
responses:
200:
description: A list of posts
schema:
type: array
items:
required:
- firstName
properties:
firstName:
type: string
lastName:
type: string
email:
type: string
comment:
type: string
post:
summary: Adds a comment to the guestbook
description: Adds a comment to the guestbook
parameters:
- name: firstname
in: formData
required: true
type: string
- name: lastname
in: formData
required: true
type: string
- name: email
in: formData
required: true
type: string
- name: comment
in: formData
required: true
type: string
responses:
201:
description: Shows a successful post
'405':
description: Invalid input
/guestbook/{id}:
get:
summary: Gets a single post
description: Returns a single post
operationId: getPost
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
200:
description: A list of posts
schema:
type: array
items:
required:
- firstName
properties:
id:
type: number
firstName:
type: string
lastName:
type: string
email:
type: string
comment:
type: string
delete:
summary: Removes a post
description: Removes a post
operationId: deletePost
parameters:
- name: id
in: path
responses:
200:
description: Post has been removed
You just need to describe the id parameter in the delete /guestbook/{id} operation just like you did in get /guestbook/{id}.
delete:
summary: Removes a post
description: Removes a post
operationId: deletePost
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
200:
description: Post has been removed
You can also define this parameter once for all operations of path /guestbook/{id}:
/guestbook/{id}:
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
get:
summary: Gets a single post
description: Returns a single post
operationId: getPost
responses:
200:
description: A list of posts
schema:
type: array
items:
required:
- firstName
properties:
id:
type: number
firstName:
type: string
lastName:
type: string
email:
type: string
comment:
type: string
delete:
summary: Removes a post
description: Removes a post
operationId: deletePost
responses:
200:
description: Post has been removed
If you need to learn how to write OpenAPI (fka. Swagger) specification files, you can read my Writing OpenAPI/Swagger Specification Tutorial

Swagger POST body list

I've been searching fruitlessly on how to swagger spec a POST body with a list inside of it. How do I do it? Here's what I have:
/groups:
post:
summary: Creates a group
parameters:
- name: body
in: body
schema:
properties:
name:
type: string
description:
type: string
groupType:
type: string
enum: [ "open", "closed", "secret" ]
users:
type: string list # <--------- a list of strings
responses:
201:
description: Group created
default:
description: Group creation failed
For property being an array of string, please refer to https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L660 as an example:
photoUrls:
type: array
items:
type: string

Resources