openapi_enum_patch 1.2.0
openapi_enum_patch: ^1.2.0 copied to clipboard
Prepare an OpenAPI export for code generation, give real names to the integer enums swagger_parser generates from it, fill in the enum files it skips, and audit which enums still need naming.
Changelog #
1.2.0 #
- New
preparecommand: rewrites an export into a shape a generator can make usable code out of, beforenormalizeruns. Four opt-in passes, each idempotent, driven by a newschema_prep.yaml:rename_schemas— exporters that inline their nested models name the resulting component after a hash of its shape (e36568fca95941d68bfb36b27ea0de7e), which generates a class nobody can read or import on purpose. Only the project knows what each one means, so the names come from config; every$refis rewritten with them, and two entries may share a target so an exporter's duplicate shapes collapse onto one component.hoist_enums— the same enum written inline on several properties generates one anonymousEnum0,Enum1, … per occurrence. Each occurrence whose values match becomes a$refto a single named component.json_only_requests— one request body declared under JSON, form-encoded and multipart makes the generator pick multipart, turning a plain POST into a per-field part list with no request model. The exact duplicates of the JSON schema are dropped; a media type declaring its own schema is left alone.strip_response_envelopes— where the transport already strips a{code, message, data, is_success}wrapper, the response is pointed at its payload$refso the client deserialises what actually reaches it. A schema qualifies only when every property it declares is a known envelope field, so a real model is never mistaken for a wrapper.
- Passes can be limited with
tags:; the component passes then only touch the components those operations reach, so a schema shared with an unimplemented route is never rewritten on its behalf. preparereports the hash-named components still in scope that it was given no name for, so the next run can name them instead of shipping the hash.- New
--prep/-poption (defaults toschema_prep.yaml; a missing file is not an error). NewSchemaPreparer,PreparationResult,SchemaPrep,SchemaPrepsandEnumPatcher.prepareSchemas, all exported. audit --strictnow exits non-zero when the audit is not clean, as its help text always said. Previously--strictwas honoured bypatchonly, so the read-only CI gate silently passed.- README rewritten around the pipeline: the seven stages in order and what each
one touches, the
scripts/generate_api.shrunner to copy, what a run prints (first run and second), where the three config files live and which command reads which, and how to gate CI onaudit --strictplus a clean tree.
1.1.0 #
- Schemas may now be YAML as well as JSON. Every command reads both, and a
project can mix the two — the format comes from the file extension
(
.yaml/.yml/.json), falling back to sniffing the content for anything else. normalizewrites each schema back in the format it read it in, so a YAML schema stays YAML. Multi-line strings are re-emitted as|-blocks and sequences keep the indentation OpenAPI exporters use, so the rewrite stays a small diff. Comments are not preserved.- New
SchemaCodec,SchemaFormatandYamlEncoder, all exported.RegistryBuilder.decodetakes an optionalformat, and there is abuildFromYamlbesidebuildFromJson. SchemaFormatExceptionmoved fromregistry_builder.darttoschema/schema_codec.dart. No change if you import the package's single public library.- Fixed
--versionreporting0.2.0.
1.0.0 #
First stable release. The API has settled across the normalize, patch,
audit and reorganize commands, so the package now commits to semantic
versioning — no breaking changes without a 2.0.0.
- Breaking: the SDK constraint is now
^3.13.0. Verified against Dart 3.13.0 and Flutter 3.47.0. - Reformatted the whole package with the Dart 3.7+ formatter ("tall style"). Formatting only — no behaviour changes.
- Bumped
args,meta,path,yaml,lintsandtestto current.
0.2.0 #
- Added the
reorganizecommand: groups the flat modelsswagger_parseremits into per-namespace folders, routes enums into anenums/subfolder, and strips the now-redundant namespace prefix from type names — rewriting every relative import,partdirective, model URI and type reference across your sources. Cross-service name collisions keep their prefix so the result still compiles. Idempotent. - Namespace groups are derived from the schema keys via
RegistryBuilder.namespacePrefixes, so nothing has to be hard-coded; passgroupstoreorganizeModelsto override. - Breaking: the
--configand--overridesdefaults are nowswagger_parser.yamlandenum_overrides.yamlat the project root, instead of paths under aswagger_tools/folder. Pass-c/-oif your files live elsewhere.
0.1.0 #
Initial release.
patchcommand — synthesises the enum filesswagger_parserskips for query-parameter-only enums, and appliesenum_overrides.yamlto the rest.normalizecommand — rewrites{version}path templates to a concrete version and qualifies barecomponents.schemasnames with a namespace prefix, rewriting every matching$ref. Both passes are idempotent.auditcommand — reports integer enums with no override, overrides that do not name every value, and overrides naming values the schema dropped.--strictmakes a non-clean audit exit non-zero, for CI.- Library API —
RegistryBuilder,EnumAuditor,SchemaNormalizer,EnumPatcher— with anEnumEmitterinterface for non-dart_mappableback-ends. - Emitted compute helpers use the
dart_mappablemapper API (XMapper.fromValue,toValue()), which works whenenums_to_json: false.