mattpolzin / mattpolzin/OpenAPIReflection
Respecting JSONEncoder's keyEncodingStrategy
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 18
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
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:
- Create a JSONEncoder with the following:
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
- Create a sample model
struct SampleObject: Codable, Sampleable, OpenAPIEncodedSchemaType {
let sampleKey: String
let sampleValue: String
}
- Initialize the model with any values and use the SampleObject's
openAPISchema(_:)to generate the schema. - Verify the keys of the model as
sampleKeyandsampleValueinstead ofsample_keyandsample_value.
Expected:
The expected result should be having the keys as sample_key and sample_value.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at OpenAPIEncodedSchemaType.openAPISchema(using encoder: JSONEncoder) and reproduce the issue with JSONEncoder.keyEncodingStrategy set to .convertToSnakeCase and the SampleObject shown. Done means the generated JSONSchema uses sample_key and sample_value rather than the Swift property names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100