skip to content
Alvin Lucillo

Initial files to generate with OpenAPI generator

/ 1 min read

Yesterday, I defined basic generator configuration for HTTP router in Go. Before you can use the generator, you need to set up your specifications.

.
├── openapi
   ├── components
   └── schemas.yaml
   ├── config
   └── go-server.yaml
   ├── openapi.yaml
   └── paths
       └── journals.yaml

It all starts with openapi.yaml, which is the input spec in the go-server generator and the main specification. This is basically the starting point of your paths definition. The generator will read all referenced files. In the example below, the path /journals use journals.yaml as reference.

openapi: 3.0.3
info:
  title: Journal API
  version: 0.1.0
servers:
  - url: http://localhost:8080
paths:
  /journals:
    $ref: "./paths/journals.yaml"

journals.yaml defines a post method for the /journals path defined above.

post:
  summary: Create a journal
  operationId: CreateJournal
  requestBody:
    required: true
    content:
      application/json:
        schema:
          $ref: "../components/schemas.yaml#/JournalEntryCreate"
  responses:
    "201":
      description: Created
      content:
        application/json:
          schema:
            $ref: "../components/schemas.yaml#/JournalEntry"