Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAPI 3.0 file format giving error around allowedValues in parameters

I've API Spec specified in OAS 3.0

post:
  tags:
    - One Time Payment
  summary: One Time Payment API
  operationId: oneTimePaymentUsingPOST
  parameters:
    - in: body
      name: realTimePaymentRequest
      description: realTimePaymentRequest
      required: true
      schema:
        $ref: '#/components/schemas/RealTimePaymentRequest'

When I edit this spec file in https://editor.swagger.io/ - It's throwing errors as :

Structural error at paths./banks/payments.post.parameters.0.in
should be equal to one of the allowed values
allowedValues: path, query, header, cookie

I can see that describing in: body in parameters is supported as per https://swagger.io/docs/specification/2-0/describing-request-body/

thought Swagger Editor is throwing errors. What could be wrong here ? schema ?

Any help is appreciated. Thank you.

like image 934
Enigma Avatar asked Feb 14 '20 09:02

Enigma


People also ask

What are the formats supported by OpenAPI swagger for their definitions?

Format. An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML format.

What are OpenAPI parameters?

In OpenAPI 3.0, parameters are defined in the parameters section of an operation or path. To describe a parameter, you specify its name , location ( in ), data type (defined by either schema or content ) and other attributes, such as description or required . Here is an example: paths: /users/{userId}:

Is OpenAPI 3.0 backwards compatibility?

OpenAPI 3 is the successor of the widely used OpenAPI/Swagger 2.0 format, for machine-readable API definitions. It contains a variety of changes, and even though everything that can be expressed in Version 2 is supported in Version 3 as well, specifications are not backwards-compatible.

How are global parameters defined in OpenAPI?

The most you can do is define these parameters in the global parameters section (in OpenAPI 2.0) or the components/parameters section (in OpenAPI 3.0) and then $ref all parameters explicitly in each operation. The drawback is that you need to duplicate the $ref s in each operation.


1 Answers

In OpenAPI 3.0, in: body and in: formData parameters were replaced with requestBody:

post:
  tags:
    - One Time Payment
  summary: One Time Payment API
  operationId: oneTimePaymentUsingPOST

  requestBody:
    description: realTimePaymentRequest
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/RealTimePaymentRequest'

The documentation link you posted is for OpenAPI 2.0. For OpenAPI 3.0, use this link:
https://swagger.io/docs/specification/describing-request-body/

like image 162
Helen Avatar answered Oct 04 '22 22:10

Helen