RAML specification Traits issue - mule

I get this syntax error, while I'm using the traits two times in the resource(one in the header part and another one is in the response part),I'm trying to fix it, but unable to do it.
error is :
is:
-Responsemessage
Hence below is the RAML specification.
#%RAML 1.0
title: RAML_Project
traits:
Responsemessage:
responses:
200:
body:
application/json:
example: {"Statuscode": 1,"message" :"Success done by traits "}
client-id-required:
headers:
client_id:
type: string
required: true
secret_key:
required: true
type: string
/QueryActivity:
get:
is:
- client-id-required
queryParameters:
Fistname:
type: string
required: true
is:
-Responsemessage
/QuerybyEmpid:
get:
body:
application/json:
type: !include dataType.raml
is:
- Responsemessage

-Responsemessage is missing the space between the - and the R. Also you seem to have 2 is: facets in the same resource. Thie - is the YAML array notation. I recommend to instead use the simpler array notation with [] instead:
/QueryActivity:
get:
is: [client-id-required, Responsemessage]
queryParameters:
Fistname:
type: string
required: true

Related

In OAS3.0, Can you set the required fields in a request body of fields in a "oneOf" or "anyOf"

This question relates to Open API spec 3 and writing API specifications.
I have been trying to work out how to set fields as required for a specific method requestBody when I am using a "oneOf" in a schema object.
I know how to set required fields of a referenced object, but when you try set the required properties of oneOf objects the same way, it does not work.
I also know that I can set the required fields in the schema object itself, however I do not want to do this as the required fields differ on each method (i.e all fields required for a post, but only some required for a patch).
So essentially, how do I set the required fields in a request body of a schema used in oneOf?
I have created an example below, in it, I want to:
Set the fields Bird - wingSpan and beakLength as required in the Post method
Set the fields Cat - tailLength as required in the Post method
Not have any required fields for Bird and Cat in the Patch method.
openapi: 3.0.3
servers:
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/Enable-Networks/TroubleTicket/1.0.0
info:
title: Pet API
version: 1.0.0
paths:
/pet:
patch:
summary: Update a pet
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
required:
- age
responses:
"204":
description: The request was a success and the pet was successfully created.
post:
summary: Create a pet
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
required:
- name
- age
- species
properties:
species:
type: object
required:
- ???
responses:
"204":
description: The request was a success and the pet was successfully created.
components:
schemas:
Cat:
type: object
properties:
tailLength:
type: integer
whiskerLength:
type: integer
Bird:
type: object
properties:
wingSpan:
type: integer
beakLength:
type: integer
highestAltitude:
type: integer
Pet:
type: object
properties:
name:
type: string
age:
type: string
species:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Bird'
Any help on this would be appreciated!
I have read the documentation 10x, tried everything from discriminators to not using refs.
I have tried many different combinations of the below and still nothing works.
requestBody:
required: true
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/Pet"
- type: object
required:
- name
- age
- species
properties:
species:
type: object
required:
- ???

Does a POST method create a new entity, and return the id of that entity, in openapi 3.0.2?

I understand that a POST method in openapi 3.0.2 is supposed to create a new entity, and return the id of that entity. When I add an additional route to GET or DELETE that entity by ID, I get a 404 error. I don't quite know why that might be.
Here are my post and get methods:
/api/globalorderdays:
post:
tags:
- Setup Global Order Days
summary: Allows user to add order days and holidays to multiple
sessions.
requestBody:
required: true
description: put text here
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
responses:
201:
description: Created
400:
description: Bad request
401:
description: Unauthorized
/api/globalorderdays/{Id}:
get:
tags:
- Setup Global Order Days
summary: put text here
parameters:
- in: path
name: Id
required: true
description: put text here
schema:
type: integer
example:
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/GlobalOrderSetupInfo'
400:
description: Bad request
401:
description: Unauthorized
/api/globalorderdays/{Id}:
delete:
tags:
- Setup Global Order Days
summary: Allows user to delete added order days
parameters:
- in: path
name: Id
required: true
description: put text here
schema:
type: integer
example:
responses:
204:
description: Deleted
400:
description: Bad request
401:
description: Unauthorized
Here are the components:
GlobalOrderSetupInfo:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
nullable: true
AvailableHolidayList:
type: string
nullable: true
SelectedOrderHolidays:
type: string
nullable: true
SelectedHolidays:
type: string
nullable: true
OrderDays:
type: string
nullable: true
NoOrderDays:
type: string
nullable: true
AllSessionList:
uniqueItems: false
type: array
items:
$ref: '#/components/schemas/SessionInfoList'
SessionIdString:
type: string
nullable: true
SessionInfoList:
description: 'Put Text Here'
type: object
properties:
Id:
type: integer
nullable: true
SessionID:
type: integer
nullable: true
Name:
type: string
nullable: true
Type:
type: string
GroupName:
type: string
IsChecked:
type: boolean
default: false
SetupID:
type: string
nullable: true
I expect to be able to retrieve/delete the entity by Id, but I return 404 errors
There are several issues with your spec.
The /api/globalorderdays/{Id} path is repeated several times. This is not valid.
# Incorrect
/api/globalorderdays/{Id}:
get:
...
/api/globalorderdays/{Id}:
delete:
...
Instead, specify the path once and list all of its HTTP methods below it, like so:
/api/globalorderdays/{Id}:
get:
...
delete:
...
Parameter examples are missing the value:
schema:
type: integer
example: # <-----
A missing value in YAML is an equivalent of null, but null is not a valid example for an integer schema. Either add a proper integer example, such as example: 1, or remove the example keyword from those schemas.
Once these issues are fixed, the mocks for GET and DELETE will work properly.

How can I declare the response array type for OpenAPI definition with JAX-RS?

I'm building a REST service with JAX-RS, Microprofile and Payara 5. My method returns an object of type Response. The response itself contains a List of MyClass. The implementation looks like this:
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
#GET
#Path("/{a}/{b}/{c}")
#APIResponse(content = #Content(schema = #Schema(type = SchemaType.ARRAY, implementation = MyClass.class)))
public Response getMyClass(#PathParam("a") String a,
#PathParam("b") String b,
#PathParam("c") String c) {
return Response
.ok()
.entity(new ArrayList<>())
.build();
}
The generated OpenAPI definition looks like this:
/api/translations/{a}/{b}/{c}:
get:
operationId: getMyClass
parameters:
- name: a
in: path
required: true
style: simple
schema:
type: string
- [...]
responses:
default:
description: Default Response.
content:
'*/*':
schema:
type: array
items: {}
As you can see, the definition of MyClass.class is missing in the response type. How can I add that type to the definition? Is the #ApiResponse annotation the correct way to achieve this?
I tested this today with the newest payara 5.191 and it did not worked for me too.
It seems that there is a bug in the current payara implementation, because I checked the example on this page guide-microprofile-openapi
The same implementation has 2 different openapi generations (Payara and OpenLiberty)
Payara:
openapi: 3.0.0
info:
title: Deployed Resources
version: 1.0.0
servers:
- url: https://10.0.0.72:8080/ipma
description: Default Server.
paths:
/resources/server:
get:
summary: List servers.
description: 'Returns all servers '
operationId: getServers
responses:
default:
description: Special description
content:
application/json:
schema:
type: array
/resources/server/{id}:
get:
summary: get server by id.
description: 'return one server with the specified id'
operationId: getServerById
parameters:
- name: id
in: query
style: simple
schema:
type: number
responses:
default:
description: Special description
content:
application/json:
schema:
$ref: '#/components/schemas/Server'
components:
schemas:
Server:
properties:
name:
type: string
example: test
id:
type: number
example: "0"
description: foo
OpenLiberty:
openapi: 3.0.0
info:
title: Deployed APIs
version: 1.0.0
servers:
- url: http://localhost:9080
paths:
/resources/server/{id}:
get:
summary: get server by id.
description: 'return one server with the specified id'
operationId: getServerById
parameters:
- name: id
in: query
schema:
type: integer
format: int64
responses:
default:
description: Special description
content:
application/json:
schema:
$ref: '#/components/schemas/Server'
/resources/server:
get:
summary: List servers.
description: 'Returns all servers '
operationId: getServers
responses:
default:
description: Special description
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Server'
components:
schemas:
Server:
required:
- id
- name
type: object
properties:
id:
type: integer
format: int64
example: 0
name:
type: string
example: test
description: foo

Swagger Editor: How to define simple response string and redirect

Defining responses in swagger is easy:
responses:
# Response code
200:
description: Successful response
schema:
title: OK
type: array
items:
title: Person
type: object
properties:
name:
type: string
single:
type: boolean
How I can return simple string and not an array
What if API endpoint makes a redirect, actually in my case redirecting is the successful attempt.
Let's skip the fact that redirecting in an API is a non-professional thing!
Update: Responding with a string is easy too:
description: A simple string response
schema:
type: string

Swagger POST with non-json body

I'm defining a resource that you POST to with a non-JSON body. It's just a string like form parameters. Something like what happens with OAuth:
grant_type=&code=&redirect_uri=
How can I document that on Swagger? Do I have to use formParam format instead of body? Everything I put into body it converts to JSON examples.
TokenRequest:
properties:
grant_type:
type: string
description: OAuth Grant Type
enum:
- authorization_code
- refresh
code:
type: string
description: Authorization Code obtained from /authorize required if grant_type = au
redirect_uri:
type: string
description: Defined Redirect URI Example - https://example.com/callback
refresh_token:
type: string
description: Required if grant_type = refresh
Here is an example on how to document the form data:
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
consumes:
- application/x-www-form-urlencoded
produces:
- application/xml
- application/json
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
type: integer
format: int64
- name: name
in: formData
description: Updated name of the pet
required: false
type: string
- name: status
in: formData
description: Updated status of the pet
required: false
type: string
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
But in your case, it seems you want to define OAuth setting so please refer to Swagger Spec 2.0 for more information. Here is an example for PetStore:
securityDefinitions:
petstore_auth:
type: oauth2
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
flow: implicit
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
in: header