mattpolzin / mattpolzin/OpenAPIReflection

Respecting JSONEncoder's keyEncodingStrategy

Open
#5 2 comments 0 reactions 0 assignees View on GitHub

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:

  1. Create a JSONEncoder with the following:
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
  1. Create a sample model
struct SampleObject: Codable, Sampleable, OpenAPIEncodedSchemaType {
    let sampleKey: String
    let sampleValue: String
}
  1. Initialize the model with any values and use the SampleObject's openAPISchema(_:) to generate the schema.
  2. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.