How to write swagger yaml in swagger editor

Viewed 25

Hi I wanted to create swagger opn api client code after writing swagger yaml on swagger editor, When I am trying to write it is throwing several errors again and again.

openapi: 3.0.0

info:
  description: |
    Rest Server API .
  version: 1.0.0-oas3
  title: Implementation of GET API in Swagger
  
paths:
  /details/:
    get:
       parameters:
      - name: details
        in: path
        schema:
          type: string
          enum: ['all', 'message', 'successfulCalls','failedCalls']
          default: all
        required: true

    definitions:
      details:
        type: object
        properties:
          details_name_test:
            type: array
            items:
              $ref: '#/definitions/Call'
      Call:
        type: int
    responses:
      '200':
        description: A list of calls (maybe filtered by details)
        schema:
          $ref: '#/definitions/details'
          properties:
                  message:
                    type: string

      '400':
        description: 'Invalid request'
        schema:
          $ref: '#/definitions/details'
          properties:
                  message:
                    type: string

Can someone please help me to fix it?

1 Answers

If you use openapi-generator, you can validate your openapi file before generating.

usage: openapi-generator-cli <command> [<args>]

The most commonly used openapi-generator-cli commands are:
    author        Utilities for authoring generators or customizing templates.
    batch         Generate code in batch via external configs.
    config-help   Config help for chosen lang
    generate      Generate code with the specified generator.
    help          Display help information about openapi-generator
    list          Lists the available generators
    meta          MetaGenerator. Generator for creating a new template set and configuration for Codegen.  The output will be based on the language you specify, and includes default templates to include.
    validate      Validate specification
    version       Show version information used in tooling

See 'openapi-generator-cli help <command>' for more information on a specific command.
java -jar openapi-generator-cli-6.0.0.jar validate -i <your_openapi_file.yaml>

If your schema is valid, you can generate the code with jar file or docker.

Docker example:

docker run --rm \
    -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/<your_openapi_file.yaml> \
    -g <choose_generator> \
    -o /local/generated/
Related