Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent openAPI spec generation for the optional status code in return #7452

Open
lnash94 opened this issue Dec 9, 2024 · 0 comments · Fixed by ballerina-platform/openapi-tools#1801

Comments

@lnash94
Copy link
Member

lnash94 commented Dec 9, 2024

Description

No response

Steps to Reproduce

In the below ballerina code[1], we expected to generate OAS[2] , but we receive OAS[3],
when using Ballerina 2201.8.6 we received code[2] and when using Ballerina 2201.9.0 and 2201.10.3 we received code[3]

import ballerina/http;

 public type BadRequestRecord record {|
    *http:BadRequest;
    string body;
 |};


service /payloadV on new http:Listener(9090) {
 
    # resource has 3 status codes that explicitly returns (202, 404, 400) while ? type returns implicitly 400, 202
    resource function post path(string id) returns http:Accepted|http:NotFound|BadRequestRecord? {
    };

}

[2] Expected code generation

openapi: 3.0.1
info:
  title: PayloadV
  version: 0.0.0
servers:
  - url: "{server}:{port}/payloadV"
    variables:
      server:
        default: http://localhost
      port:
        default: "9090"
paths:
  /path:
    post:
      summary: "resource has 3 status codes that explicitly returns (202, 404, 400)\
        \ while ? type returns implicitly 400, 202"
      operationId: postPath
      parameters:
        - name: id
          in: query
          required: true
          schema:
            type: string
      responses:
        "202":
          description: Accepted
        "404":
          description: NotFound
        "400":
          description: BadRequest
          content:
            text/plain:
              schema:
                type: string
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorPayload'
components:
  schemas:
    ErrorPayload:
      type: object
      properties:
        reason:
          type: string
          description: Reason phrase
        path:
          type: string
          description: Request path
        method:
          type: string
          description: Method type of the request
        message:
          type: string
          description: Error message
        timestamp:
          type: string
          description: Timestamp of the error
        status:
          type: integer
          description: Relevant HTTP status code
          format: int32

[3] Generated Payload

openapi: 3.0.1
info:
  title: PayloadV
  version: 0.0.0
servers:
  - url: "{server}:{port}/payloadV"
    variables:
      server:
        default: http://localhost
      port:
        default: "9090"
paths:
  /path:
    post:
      summary: "resource has 3 status codes that explicitly returns (202, 404, 400)\
        \ while ? type returns implicitly 400, 202"
      operationId: postPath
      parameters:
        - name: id
          in: query
          required: true
          schema:
            type: string
      responses:
        "202":
          description: Accepted
          content:
            application/json:
              schema: {}
        "404":
          description: NotFound
        "400":
          description: BadRequest
          content:
            text/plain:
              schema:
                type: string
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorPayload'
components:
  schemas:
    ErrorPayload:
      type: object
      properties:
        reason:
          type: string
          description: Reason phrase
        path:
          type: string
          description: Request path
        method:
          type: string
          description: Method type of the request
        message:
          type: string
          description: Error message
        timestamp:
          type: string
          description: Timestamp of the error
        status:
          type: integer
          description: Relevant HTTP status code
          format: int32

Please enable these two cases, once we clarify the correct behaviour

  • testResponseWithReadOnlySimpleNameReferenceReturnType
  • testNilUnionReturnType

Version

2201.8.6 - 2201.10.3

Environment Details (with versions)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant