nullable fields in swagger on node.js

前端 未结 4 698
[愿得一人]
[愿得一人] 2021-01-04 02:42

I\'ve spent a bunch of time trying to find a solution for creating swagger docs in Node.JS. The main library is swagger-node, in which you create a swagger yaml file and the

4条回答
  •  余生分开走
    2021-01-04 02:54

    Just as a hint, because I stumpled upon this: When I added

    type: string
    nullable: true`
    

    as described in the answer https://stackoverflow.com/a/42797352/2750563 my service returned only "fieldName": { "present": true } instead of an actual value!

    If you see this, simply add the JsonNullableModule to your Jackson serializer, for example, if using Spring:

    @Component
    public class JacksonConfiguration {
    
        @Autowired
        public void configureJackson(ObjectMapper mapper) {
            mapper.registerModule(new JsonNullableModule());
        }
    
    }
    

    Then everything looks fine again.

提交回复
热议问题