1 Star 1 Fork 0

networknt/light-example-4j

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Nullable Value Demo

This is a demo to show users how to construct OpenAPI specification to allow certain field to be null. If only one data type is defined and a null value is passed in, the built-in JSON schema validator will report an error.

In this demo we have a post endpoint with start date in the body. In order to allow startDate to be null, we have to define this field in yaml as

     startDate:
        type:
        - "string"
        - "null"
        format: "date"

And corresponding JSON field is

                "startDate": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "format": "date"
                },

Start server

Run with

mvn package exec:exec
``

## Test

As this is just a simple demo, no security definitions in the spec. The post
endpoint url is

localhost:8080/v1/data


Header Content-Type must be set as application/json

Content-Type=application/json


And you can use this JSON object as request body.

{ "id": 123, "name": "king", "weight": 76.22, "startDate": null }

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/networknt/light-example-4j.git
git@gitee.com:networknt/light-example-4j.git
networknt
light-example-4j
light-example-4j
master

搜索帮助