swagger-api / swagger-api/swagger-parser

OpenAPI v2 converter: parameter name is lost

Open
#748 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

When the parser is doing the conversion from OAS2 to OAS3, a parameter of type in: "body" in OAS2 is converted to a requestBody in OAS3.

Example:

OAS2:

      - name: "requestList"
        in: "body"
        description: "Requests to post"
        required: true
        schema:
          $ref: "#/definitions/listitems"

OAS3:

      requestBody:
        description: Requests to post
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/listitems'
        required: true

During the operation, the parameter name is lost. Would it be possible to have a x-name added to the request body, in order to keep the information of the OAS2?

Expected result after the change?

      requestBody:
        x-name: "requestList"
        description: Requests to post
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/listitems'
        required: true

If you are interested I might be able to propose a PR for that.
Thank you in advance for your answer.


Complete input example:

swagger: "2.0"
info:
  description: Container Application Model Description
  version: 1.0.0
  title: ContainerApplication
  
host: localhost:32000
basePath: /api/v1.0
schemes:
- http

tags:  
- name: ApplicationEndpointTest
  x-displayName: "ApplicationEndpointTest"
  description: |
    "Test of endpoints "
    
paths:
  /default/EndpointTest: 
    post:
      tags:
      - ApplicationEndpointTest      
      description: "post a request"
      operationId: callEndpoint
      consumes:
      - application/json
      parameters:
      - name: "requestList"
        in: "body"
        description: "Requests to post"
        required: true
        schema:
          $ref: "#/definitions/listitems"
      responses:
        200:
          description: "Successful response"
        404:
          description: "The request was not successfully executed."
      
  
definitions:
  listitems : 
    description: "list of items"
    type: array
    items: 
      type: "string"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the parser's OAS2-to-OAS3 conversion of body parameters, using the complete Swagger input example in the issue. Verify that the converted requestBody preserves the original parameter name as x-name: requestList, while retaining the shown description, content, schema, and required values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.