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

Parameter example is undefined for $ref schema parameters #627

Closed
homemdasneves opened this issue Oct 1, 2022 · 2 comments · Fixed by #680
Closed

Parameter example is undefined for $ref schema parameters #627

homemdasneves opened this issue Oct 1, 2022 · 2 comments · Fixed by #680
Assignees
Labels
bug Something isn't working good-first-issue Good first issues that can be picked up by beginner contributors. importer parameter-object

Comments

@homemdasneves
Copy link

If a spec has a reference schema parameter with an example like sortDirection here:

"/api/v1/application/Area/list": {
      "post": {
        "tags": [
          "Area"
        ],
        "summary": "Retrieve a list of records of entity type",
        "operationId": "Area_GetMany",
        "parameters": [
          {
            "name": "sortDirection",
            "in": "query",
            "description": "Direction to sort by",
            "schema": {
              "$ref": "#/components/schemas/SortDirection"
            },
            "example": "asc"
          },
...

we won't get "asc" in the value, we'll get <string> instead:

{
    "id": "c9dbad06-eeb4-4771-8d8e-5b471483b9e5",
    "name": "Retrieve a list of records of entity type",
    "request": {
        "name": "Retrieve a list of records of entity type",
        "description": {},
        "url": {
            "path": [
                "api",
                "v1",
                "application",
                "Area",
                "list"
            ],
            "host": [
                "{{baseUrl}}"
            ],
            "query": [
                {
                    "disabled": false,
                    "key": "sortDirection",
                    "value": "<string>",
                    "description": "Direction to sort by"
                },
...

But, if the schema is inline, like below:

"/api/v1/application/UnitType/list": {
      "post": {
        "tags": [
          "UnitType"
        ],
        "summary": "Retrieve a list of records of entity type",
        "operationId": "UnitType_GetMany",
        "parameters": [
          {
            "name": "sortDirection",
            "in": "query",
            "description": "Direction to sort by",
            "schema": {
              "enum": [
                "asc",
                "desc"
              ],
              "type": "string"
            },
            "example": "asc"
          },

the value is correctly filled as asc in the generated postman collection:

{
    "id": "b4a0b4df-ed78-4245-ac62-17dc4f5c2775",
    "name": "Retrieve a list of records of entity type",
    "request": {
        "name": "Retrieve a list of records of entity type",
        "description": {},
        "url": {
            "path": [
                "api",
                "v1",
                "application",
                "UnitType",
                "list"
            ],
            "host": [
                "{{baseUrl}}"
            ],
            "query": [
                {
                    "disabled": false,
                    "key": "sortDirection",
                    "value": "asc",
                    "description": "Direction to sort by"
                },
...

As a workaround, in order to have a valid value upon generation, we can set a default value in the $ref schema parameter.

This could be related with #401 and #559

@VShingala
Copy link
Member

@homemdasneves Could you also add the schema for SortDirection component? We validate the value defined against the corresponding schema and if example is not valid according to schema then depending upon option we use random value or <string> as a placeholder.

@VShingala VShingala added the bug Something isn't working label Jan 13, 2023
@VShingala
Copy link
Member

VShingala commented Jan 13, 2023

Issue is reproducible with following schema.

openapi: '3.0.0'
info:
  version: '1.0.0'
  title: 'Sample API'
  description: Buy or rent spacecrafts

paths:
  /spacecrafts/{spacecraftId}:
    parameters:
      - $ref: '#/components/parameters/args.userId'
    get:
      summary: Read a spacecraft
      parameters:
        - name: hello
          in: query
          description: Direction to sort by 1
          schema:
            type: string
          example: asc
        - name: world
          in: query
          description: Direction to sort by 2
          schema:
            $ref: '#/components/schemas/SpacecraftId'
          example: asc
      responses:
        '200':
          description: The spacecraft corresponding to the provided `spacecraftId`
          content:
            application/x-www-form-urlencoded:
              schema:
                $ref: '#/components/schemas/Spacecraft'
            application/json:
              schema:
                $ref: '#/components/schemas/Space
components:
  parameters:
    args.userId:
      name: spacecraftId
      description: The unique identifier of the spacecraft
      in: path
      required: true
      schema:
        $ref: '#/components/schemas/SpacecraftId'
  schemas:
    SpacecraftId:
      description: The unique identifier of a spacecraft
      type: string
    Spacecraft:
      type: object
      required:
        - id
        - name
        - type
      properties:
        id:
          $ref: '#/components/schemas/SpacecraftId'
        name:
          type: string
        type:
          type: string
          enum:
            - capsule
            - probe
            - satellite
            - spaceplane
            - station
        description:
          type: string
    Error:
      type: object
      required:
        - message
      properties:
        message:
          description: A human readable error message
          type: string
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
security:
  - bearer: []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good-first-issue Good first issues that can be picked up by beginner contributors. importer parameter-object
Projects
None yet
4 participants