openapi_enum_patch 1.3.0 copy "openapi_enum_patch: ^1.3.0" to clipboard
openapi_enum_patch: ^1.3.0 copied to clipboard

Prepare an OpenAPI export for codegen, name the integer enums swagger_parser produces, generate the enum files it skips, and audit the enums that still need names.

Changelog #

1.3.0 #

  • Enum member names are now read from the export itself. OpenAPI has nowhere to put them, but most exporters write them into a vendor extension anyway, and patch now reads all three spellings: x-enum-varnames (openapi-generator, drf-spectacular), x-enumNames / x-enum-names (NSwag and the .NET exporters) and x-ms-enum (AutoRest, Azure). An export that carries them needs no enum_overrides.yaml entry at all, and the audit stops asking for one.
    • The list forms are zipped against enum, so a truncated or partly blank list names the values it reaches and the audit asks for the rest. x-ms-enum pairs each name with its value, so its order does not matter.
    • An override outranks the export value by value, so a project can rename only the members it disagrees with.
    • The audit reports how many enums took their names this way, and AuditReport.schemaNamed exposes the count. New EnumEntry.schemaNames and EnumEntry.isSchemaNamed.
  • New DUPLICATE NAMES audit issue (a new AuditIssue value, so an exhaustive switch over it in your own code needs one more case): two values resolving to one Dart member name previously emitted an enum that did not compile, with no warning. They are now emitted as name$1 / name$2 and reported, with the shared identifier named in the report. Checked for string enums too, where a schema declaring both Draft and draft folds them onto one member without any override involved.
  • Fixed: a string enum value containing $ emitted 'USD$', which Dart reads as the start of an interpolation and refuses to compile. $ is now escaped along with newlines, carriage returns and tabs.
  • Fixed: an override or schema-declared name that was not already a legal Dart identifier emitted a file the analyser rejected. Characters Dart does not allow now become _ (in progressin_progress) and a leading digit gets a $ in front of it (2fa$2fa), alongside the existing reserved-word suffix.
  • A command now loads only the config it actually reads, so a malformed enum_overrides.yaml no longer fails a normalize or reorganize run that never looks at it — and its parse error is reported with the same wording from every command.
  • The version --version prints moved to packageVersion in the library, with a test holding it to pubspec.yaml, so a release cannot ship the previous number.
  • The audit's closing line now says "fully named" rather than "fully overridden", since the names no longer have to come from an override.
  • Internals: the four copies of read-schema-decode-rewrite in EnumPatcher collapsed onto one helper, and ResolvedMembers is now the single place that decides what a member is called — the auditor asks it rather than reimplementing the rules.

1.2.1 #

  • Shorten the pubspec description to the 60–180 characters pub.flutter-io.cn scores, so the package no longer loses its "valid pubspec.yaml" points.

1.2.0 #

  • New prepare command: rewrites an export into a shape a generator can make usable code out of, before normalize runs. Four opt-in passes, each idempotent, driven by a new schema_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 $ref is 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 anonymous Enum0, Enum1, … per occurrence. Each occurrence whose values match becomes a $ref to 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 $ref so 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.
  • prepare reports 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 / -p option (defaults to schema_prep.yaml; a missing file is not an error). New SchemaPreparer, PreparationResult, SchemaPrep, SchemaPreps and EnumPatcher.prepareSchemas, all exported.
  • audit --strict now exits non-zero when the audit is not clean, as its help text always said. Previously --strict was honoured by patch only, 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.sh runner 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 on audit --strict plus 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.
  • normalize writes 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, SchemaFormat and YamlEncoder, all exported. RegistryBuilder.decode takes an optional format, and there is a buildFromYaml beside buildFromJson.
  • SchemaFormatException moved from registry_builder.dart to schema/schema_codec.dart. No change if you import the package's single public library.
  • Fixed --version reporting 0.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, lints and test to current.

0.2.0 #

  • Added the reorganize command: groups the flat models swagger_parser emits into per-namespace folders, routes enums into an enums/ subfolder, and strips the now-redundant namespace prefix from type names — rewriting every relative import, part directive, 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; pass groups to reorganizeModels to override.
  • Breaking: the --config and --overrides defaults are now swagger_parser.yaml and enum_overrides.yaml at the project root, instead of paths under a swagger_tools/ folder. Pass -c / -o if your files live elsewhere.

0.1.0 #

Initial release.

  • patch command — synthesises the enum files swagger_parser skips for query-parameter-only enums, and applies enum_overrides.yaml to the rest.
  • normalize command — rewrites {version} path templates to a concrete version and qualifies bare components.schemas names with a namespace prefix, rewriting every matching $ref. Both passes are idempotent.
  • audit command — reports integer enums with no override, overrides that do not name every value, and overrides naming values the schema dropped.
  • --strict makes a non-clean audit exit non-zero, for CI.
  • Library API — RegistryBuilder, EnumAuditor, SchemaNormalizer, EnumPatcher — with an EnumEmitter interface for non-dart_mappable back-ends.
  • Emitted compute helpers use the dart_mappable mapper API (XMapper.fromValue, toValue()), which works when enums_to_json: false.
1
likes
160
points
342
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Prepare an OpenAPI export for codegen, name the integer enums swagger_parser produces, generate the enum files it skips, and audit the enums that still need names.

Repository (GitHub)
View/report issues

Topics

#openapi #swagger #codegen #enums

License

MIT (license)

Dependencies

args, meta, path, yaml

More

Packages that depend on openapi_enum_patch