Maven openapi generator plugin generates Auth classes - swagger

I'm building a very simple API with maven plugin configuration here. But it generates some Authentication classes (auth package and some other classes like StringUtil, JSON) I've never defined in my configuration. I don't want all these classes, where do they come from ? :
Here is my student.yaml input file :
openapi: 3.0.0
info:
title: student API
description: student demo API by Anthony Errera
version: 1.0.0
paths:
/student:
description: Student Resource
get:
description: operation to fetch student
parameters:
- in: query
name: studentname
required: true
schema:
type: string
responses:
200:
description: Success response
content:
application/json:
schema:
type: array
items:
properties:
StudentID:
type: integer
example: 3
StudentName:
type: string
example: toto
post:
description: add a student
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/student'
responses:
201:
description: student created
components:
schemas:
student:
type: object
properties:
StudentID:
type: integer
example: 3
StudentName:
type: string
example: toto

Related

Swagger stating "should NOT have additional properties additionalProperty: schema" for a reusable enum

I'm trying to create an enum as a reusable object in my swagger and swagger is erroring with:
Structural error at components.schemas.Project.properties.location
should NOT have additional properties
additionalProperty: schema
Jump to line 47
I have the enum specified in the components/schemas section and I am then referencing it using $ref: '#/components/schemas/Registry'. I was trying to follow the example here: https://swagger.io/docs/specification/data-models/enums/
This is the full swagger file:
openapi: 3.0.3
info:
title: My API
description: |-
Blah
contact:
email: support#example.com
version: 1.0.0
externalDocs:
description: Find out more about blah
url: http://blah.io
paths:
/credits-received:
post:
tags:
- Credits Received
operationId: creditsReceived
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreditsReceivedData'
required: true
responses:
'200':
description: Successful operation
components:
schemas:
CreditsReceivedData:
required:
- project
type: object
properties:
project:
$ref: '#/components/schemas/Project'
Project:
required:
- name
- registry
type: object
properties:
name:
type: string
example: "Project 1"
registry:
type: string
example: "My Registry"
schema:
$ref: '#/components/schemas/Registry'
Registry:
type: string
enum:
- My Registry 1
- My registry 2
I solved this by replacing
registry:
type: string
example: "My Registry"
schema:
$ref: '#/components/schemas/Registry'
with
registry:
$ref: '#/components/schemas/Registry'
Basically remove the schema attribute, just put the $ref directly under the property (registry in this case).

OAS 3: How I can autopopulate the endpoint name into my responses?

Using swagger made the following api:
openapi: 3.0.0
servers: []
info:
description: This is a simple API
version: "1.0.0"
title: Simple API
paths:
/inventory:
get:
summary: searches inventory
description: |
By passing in the appropriate options, you can search for
available inventory in the system
parameters:
- in: query
name: searchString
description: pass an optional search string for looking up inventory
required: false
schema:
type: string
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
type: string
description: "Item names"
'400':
description: bad input parameter
content:
application/json:
schema:
type: object
properties:
'/inventory':
type: boolean
message:
type: string
/baka:
get:
responses:
400:
description: "ERROR"
content:
application/json:
schema:
type: object
properties:
'/baka':
type: boolean
message:
type: string
As you can see I use the following pattern for my error responses:
endpoint_name: boolean
message: string
So how I can create a common response object that swagger will auto-populate with endpoint name?

Hello,I am using swagger 3.0.0.The operation oneOf is not working here too?Where is the mistaken?

here is the code.When I write allOF instead oneOF then everything is ok,but with oneOf it doesn't show anything and there is no error.Did I write something wrong or it is still not working in swagger 3.0.0.Also any of is not woking.Or do we have something like oneOf but in swagger 2.0
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
x-origin:
- url: 'http://petstore.swagger.io/v2/swagger.json'
format: swagger
version: '2.0'
converter:
url: 'https://github.com/mermade/swagger2openapi'
version: 2.2.0
info:
description: 'This is a sample.'
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam#swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
paths:
/something:
post:
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Cat'
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
swagger-ui-express 4.1.12 not supporting oneof,anyof version
openapi: 3.0.1
tags:
- name: API Specification
description: All endpoints and payloads about Project
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer

How to send the Default value through body in Swagger 2.0

Hi i am trying to send the Default values through body parameters but its Not taking while Submitting. can anybody please help me on this issue. Here is my code and i am trying to send the default name parameter through body
swagger: '2.0'
info:
version: 1.0.0
title: PetStore on Heroku
description: |
**This example has a working backend hosted in Heroku**
You can try all HTTP operation described in this Swagger spec.
Find source code of this API [here](https://github.com/mohsen1/petstore-api)
host: petstore-api.herokuapp.com
basePath: /pet
schemes:
- http
- https
consumes:
- application/json
- text/xml
produces:
- application/json
- text/html
paths:
/:
get:
parameters:
- name: limit
in: query
description: number of pets to return
type: integer
default: 0
responses:
200:
description: List all pets
schema:
title: Pets
type: array
items:
$ref: '#/definitions/Pet'
post:
parameters:
- name: pet
in: body
description: The pet JSON you want to post
schema:
$ref: '#/definitions/Pet'
required: true
responses:
200:
description: Make a new pet
put:
parameters:
- name: pet
in: body
description: The pet JSON you want to post
schema:
$ref: '#/definitions/Pet'
required: true
responses:
200:
description: Updates the pet
/{petId}:
get:
parameters:
- name: petId
in: path
type: string
description: ID of the pet
required: true
responses:
200:
description: Sends the pet with pet Id
definitions:
Pet:
type: object
properties:
name:
type: string
default : "xxxxxxx"
birthday:
type: integer
format: int32
The default value should be handled in the server side as the server should not always assume the client sends HTTP requests that are 100% conforming to the spec.
I think this can help you, if you are trying to send default data with your schema:
definitions:
Pet:
type: object
default:
name: xxxx
birthday: xxxx
properties:
name:
type: string
birthday:
type: integer
format: int32

Create my own type in Swagger

I Have this YAML code of swagger and I need to create my own type (named MyOwnType).
If I use "MyOwnType" a compilation error occurs.
paths:
/in/total:
get:
summary: My summary.
description: My description.
parameters:
- name: total
in: query
description: Total.
required: true
type: MyOwnType # -- THIS LINE OCCURS ERROR --
format: MyOwnType
responses:
201:
description: Respose
schema:
$ref: '#/definitions/MyOwnType'
definitions:
MyOwnType:
properties:
var:
type: string
description: data.
I created a definition "MyOwnType" and I can use like that: "$ref: '#/definitions/MyOwnType'" in schema.
But how can I use the "MyOwnType" definition on a parameter type?
A query parameter can not have a JSON Schema. If you want to have schema for your parameter you should change in of your parameter to body or formData and use schema key:
swagger: '2.0'
info:
version: 0.0.0
title: '<enter your title>'
paths:
/in/total:
get:
summary: My summary.
description: My description.
parameters:
- name: total
in: body
description: Total.
required: true
schema:
$ref: '#/definitions/MyOwnType'
responses:
201:
description: Respose
schema:
$ref: '#/definitions/MyOwnType'
definitions:
MyOwnType:
properties:
var:
type: string
description: data.

Resources