mattpolzin / OpenAPIKit

Codable Swift OpenAPI implementation.
MIT License
280 stars 35 forks source link

Allow JSONEncoder keyEncodingStrategy #268

Closed jcbriones closed 1 year ago

jcbriones commented 1 year ago

Issue: Found an issue where when I use theOpenAPIEncodedSchemaType.openAPISchema(using encoder: JSONEncoder) to create a JSONSchema with passing an encoder that has keyEncodingStrategy set to convertToSnakeCase, the JSONSchema's keys wasn't converting the keys to use convertToSnakeCase and returning as what the variable name is set to.

How to reproduce:

  1. Create a JSONEncoder with the following:
    let encoder = JSONEncoder()
    encoder.keyEncodingStrategy = .convertToSnakeCase
  2. Create a sample model
    struct SampleObject: Codable, Sampleable, OpenAPIEncodedSchemaType {
    let sampleKey: String
    let sampleValue: String
    }
  3. Initialize the model with any values and use the SampleObject's openAPISchema(_:) to generate the schema.
  4. Verify the keys of the model as sampleKey and sampleValue instead of sample_key and sample_value.

Expected: The expected result should be having the keys as sample_key and sample_value.

jcbriones commented 1 year ago

Closing this issue and will open a new one to the correct repo. The following issue might not be all the way down to the OpenAPIKit library but more like in OpenAPIReflection