0

I want to convert some typescript types to openapi version 3. If I have an interface which is a book:

export interface Book {
  name: string;
  author: string;
  genre: "Comedy" | "Horror" | "Romance"
}

How could this be represented in an openApi spec?

I was thinking it would be similar to the following:

openapi: 3.0.0
info:
  title: Converted from types.yaml with typeconv
  version: '3'
paths: {}
components:
  schemas:
    Book:
      properties:
        title:
          type: string
        author:
          type: string
        genre:
          anyOf:
            - Comedy:
              type: string
            - Horror:
              type: string
            - Romance:
              type: string
      required:
        - title
        - author
        - genre
      additionalProperties: false
      description: "@swagger components:\r\n  schemas:\r\n    Book:\r\n      type: object\r\n      description: A book.\r\n      properties:\r\n        title:\r\n          type: string\r\n        author:\r\n          type: string\r\n        genre:\r\n          type: string"
      type: object

but I'm not using the anyOf property correctly. Is there a way of specifying that the type is a string and there are limited options to choose from?

avenmia
  • 2,015
  • 4
  • 25
  • 49
  • 1
    Does this answer your question? [How to define an enum in OpenAPI](https://stackoverflow.com/q/27603871/113116) – Helen May 19 '21 at 15:41
  • I believe that should work! If you make this an answer, I'll mark it as accepted. Thank you! – avenmia May 19 '21 at 16:14

0 Answers0