utybo / Tegral

🟣 A Kotlin framework for web applications, cool libraries that go along with it!
https://tegral.zoroark.guru
Apache License 2.0
37 stars 3 forks source link

Rewrite Swagger Core's ModelResolver #55

Open utybo opened 1 year ago

utybo commented 1 year ago

Swagger Core's ModelResolver (which takes care of converting JVM types to JSON Schema types using Jackson and with a lot of custom logic) has a bunch of problems. It is very difficult to read (the function that performs the resolution is 750+ lines long of uninterrupted, fairly complex logic!), and, on the compatibility-with-Jackson side:

The idea would be to take the original code, convert it to Kotlin, split it in more understandable functions and provide it in a separate library. This honestly sounds like a fun challenge I'd be willing to take on[^why-not-contribute].

NB, if tests are present in Swagger Core's codebase, those must be taken into account. Add a lot of test, this reimplementation must have 100% coverage because it is a critical component of conversion.

In terms of integration into Tegral, provide it as a configuration flag (tegral.experiments.useNewSwaggerModelResolver or something) for Tegral and Ktor applications.

[^why-not-contribute]: I do not wish to contribute it back to Swagger Core as I would like to implement this complex logic in Kotlin to get the cleanest code possible (and I do not know how active Swagger Core is), while the original codebase is in Java.


The game plan

Things to do

Swagger Core Tests

Tests to ignore

Because they don't test the resolver:

ATMTest

Test does not have useful assertions

BeanValidatorTest

ComplexPropertyTest

Test does not have useful assertions

ComposedSchemaTest

Test has useful assertions: yes

ContainerTest

EnumTest

HiddenFieldTest

InheritedBeanTest

JacksonJsonUnwrappedTest

ModelWithJaxBDefaultValues

JodaDateTimeConverterTest

JodaLocalDateConverterTest

JodaTest

JsonPropertyTest

ModelWithRangesTest

RequiredFieldModelTest

SimpleGenerationTest

2189

2740 (Cyclic)

2862

2884

2915

2926

2972

2992

3030

3063

3197

3348

3365

3624

3697

3699

3703

3853

3904

4290

XMLGregorianCalendarTest

XMLInfoTest

XMLModelTest

Extra things to care about

Kotlin support

Potential issues

utybo commented 1 year ago

Pushing this back to an unknown date because this is extremely boring work, and I (currently) have no interest in working on this in my free time.