oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
91 stars 51 forks source link

Add info.pattern for String and other minor fixes #27

Closed natanael closed 3 years ago

natanael commented 3 years ago
  1. Deduplicate info.description logic
  2. Add info.pattern to Strings
  3. Enable defaults for List and Enum Requires: https://github.com/oatpp/oatpp/pull/282 (already merged)
    DTO_FIELD_INFO(referral) {
    info->pattern = "^[^\\s]+$"; // This is what we set to add
    };
    DTO_FIELD(String, referral, "referral") = "direct";
    DTO_FIELD(List<String>, friends) = [](){
    auto defaultFriends = List<String>::createShared();
    defaultFriends->push_back(String("me")); // :)
    return defaultFriends;
    }(); // Poor-mans default, just for testing
    DTO_FIELD(Enum<HelloEnum>, helloEnum) = HelloEnum::V1; // We had it but it wasn't showing in swagger
    "referral": {
    "type": "string",
    "default": "direct",
    "pattern": "^[^\\s]+$" // <- Some tools can use this for validating the JSON
    },
    "friends": {
    "type": "array",
    "default": [ // <- Defaults for List<String>
        "me"
    ],
    "items": {
        "type": "string"
    }
    },
    "helloEnum": {
    "default": "value-1", // <- Defaults for Enum<T>
    "$ref": "#\/components\/schemas\/HelloEnum(String)"
    }
lganzzzo commented 3 years ago

This looks awesome! Please fix the minor comment, and I'll merge it.

lganzzzo commented 3 years ago

Aaaand it's merged 🎉

bamkrs commented 3 years ago

Keep up the good work!