3

TLDR: The problem seems to be that in swagger field should be mandatory when it is enum (Unlike java enum fields). I'm wondering if there is a way to make it optional

I'm using swagger to generate some integration api from yaml files

<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>

(by default Gson implementation is used in plugin for working with json)

In one of yaml files I have a description of request with a field which is described like this

...
definitions:
  MyRequest:
    type: object
    required:
      - field1
      - field2
    properties:
      myEnumField:
        type: string
        enum:
          - A
          - B
          - C

Or see documentation for example.

For that swagger generates public static class Adapter (by default Gson implementation is used in plugin for working with json, so this Adapter extends com.google.gson.TypeAdapter). And this implementation forbid to leave this field empty (fails with NPE in runtime otherwise).

I want to permit optional enum fields for all yaml files, or at least for specified ones.

Thanks in advance

WeGa
  • 801
  • 4
  • 10
  • 24

0 Answers0