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?