utoipa icon indicating copy to clipboard operation
utoipa copied to clipboard

Unify `utoipa-gen` type parsing/schema production

Open kellpossible opened this issue 1 year ago • 2 comments

Representations of types/paths which are parsed into schemas are spread throughout utoipa-gen and their level of parsing support varies:

  • https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/ext.rs#L21
  • https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/ext/rocket.rs#L118
  • https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/ext/rocket.rs#L75
  • https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/lib.rs#L806 which is used in https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/path/parameter.rs#L38

It would be good to unify these somehow if possible and gain more consistent parsing and schema production support.

kellpossible avatar Jul 12 '22 09:07 kellpossible

Yes this is something that need to be addressed, Currently the implementation is quite spread out. I suggest that this would be postponed for sort time. Since the axum integration will actually address some of the issues here.

List of things should be done:

  • Split extensions to seprate crates + create corelib crate which contains types needed by the extensions
  • Move extension related tests to these new crates
  • Try to use the ComponentPart to resolve the types if possible (since it is generic type).
  • Ultimately refactor the implementation so that it is generic over all extension as much as possible.

juhaku avatar Jul 12 '22 13:07 juhaku

I'm now working on refactoring the extension related types to use one argument type and resolving logic across the extensions.

With further PR:s we could get rid of this type once and for all in and use ComponentPart instead which would enable us more centralized control for parsing. https://github.com/juhaku/utoipa/blob/6cec1029f57e3fd81d6b2c7e4680c34e482060e6/utoipa-gen/src/lib.rs#L806

juhaku avatar Jul 14 '22 22:07 juhaku