ajevans99 / swift-json-schema

Generate JSON Schema documents from Swift
MIT License
12 stars 5 forks source link

Specifying `additionalProperties` when using `@Schemable` #27

Open ptrkstr opened 1 month ago

ptrkstr commented 1 month ago

Hey @ajevans99, once again thank you for this fantastic package! I wanted to ask if there was a way to set additionalProperties (in my case false) when using the @Schemable macro. I wasn't able to find it in the source or tests but I may have missed it.

ajevans99 commented 1 month ago

Hey! Unfortunately, there isn't a way to set additional properties to false while using the Schemable macro just yet. I hope to add this in the future, but need to put a bit more thought into it. It's trickier with the applicator keywords that apply subschemas, like additionalProperties.

In the meantime, you can manually create the schema with the builders. Something like:

struct Person {
    let name: String
}

extension Person: Schemable {
   static var schema: JSONSchemaComponent {
     JSONObject {
       JSONProperty(key: "name") { JSONString() }
     }
     .disableAdditionalProperties()
   }
}
ptrkstr commented 1 month ago

Thanks for the quick reply @ajevans99 🙏 I appreciate you wanting to add it in the future and thank you for the alternative method, I will do that instead.