Skip to content

fix: widen DynamicResourceDoc example/response body columns to text- #94 - #2898

Open
hongwei1 wants to merge 3 commits into
OpenBankProject:developfrom
hongwei1:develop-obp
Open

fix: widen DynamicResourceDoc example/response body columns to text- #94#2898
hongwei1 wants to merge 3 commits into
OpenBankProject:developfrom
hongwei1:develop-obp

Conversation

@hongwei1

Copy link
Copy Markdown
Contributor

Summary

DynamicResourceDoc.ExampleRequestBody, SuccessResponseBody and ErrorResponseBodies were all MappedString(this, 255) (varchar(255)). A realistic multi-field JSON example — even with minimal values — routinely exceeds 255 characters once a payload has more than a handful of fields (field names alone can exceed the limit). Endpoints with wider payloads had no way to register an example at all via the runtime registration API, leaving API-Explorer-II's request-body editor empty for those endpoints instead of pre-filled, forcing API consumers to hand-type the JSON body from scratch every time.

Widening the columns then surfaced a second, more serious bug: any example body with a nested object crashed the entire resource-docs listing (all endpoints, not just the one with the nested field) with a NullPointerException. Both are fixed here.

Fix

  1. Widen ExampleRequestBody, SuccessResponseBody, ErrorResponseBodies from MappedString(this, 255) to MappedText(this) (unbounded), matching the existing MethodBody field's type.
    • Schemifier only creates missing tables/columns — it does not alter the type of an existing column — so an existing database needs an explicit migration. Added MigrationOfDynamicResourceDocBodyFieldsLength, following the exact pattern of the existing MigrationOfTransactionRequestAttributeValueType (same scenario: varchar(255) too small for JSON-shaped content), and wired it into Migration.database.executeScripts.
  2. Null-guard Class.getCanonicalName() in JSONFactory1_4_0.checkFieldOption. getCanonicalName() returns null for a local or anonymous class — which is exactly what a nested case class declared inside a runtime-compiled dynamic-endpoint method body is, from the JVM's perspective. Once (1) stopped forcing such examples to be omitted, any example body with a nested object (e.g. {"payer": {...}}) hit this and took down /resource-docs/.../obp for the whole API surface. Defaults to false (not Option-typed) when no canonical name is available.

Test plan

  • DynamicResourceDocTest (8/8), MigrationsTest (12/12), ResourceDocsTechnologyTest, ResourceDocsTest, SwaggerDocsTest, SwaggerFactoryUnitTest (102/102 total across the six suites) pass
  • Manually verified against a live Postgres instance: booted with the change, confirmed the migration log records execution, and confirmed via \d dynamicresourcedoc that all three columns are now text
  • Registered 9 real dynamic endpoints with example bodies ranging from flat 5-field objects up to an 851-character example with two levels of nesting; confirmed GET /resource-docs/OBPv7.0.0/obp returns 200 with all examples populated (previously 500 before the second fix, and previously omitted from the payload entirely before the first fix)
  • Confirmed a fresh boot (no existing table) creates the columns as text directly via Schemifier, and an existing database picks up the widening via the migration on next boot

ExampleRequestBody, SuccessResponseBody and ErrorResponseBodies were
capped at varchar(255), which a realistic multi-field JSON example
routinely exceeds even with minimal values. Endpoints with wider
payloads had to omit the example entirely, leaving the request-body
editor empty for API consumers instead of pre-filled.

Widen all three to unbounded text, matching MethodBody's existing type.
On an existing database this needs an explicit ALTER COLUMN migration
(Schemifier only creates missing tables/columns, it does not widen
existing ones), added as MigrationOfDynamicResourceDocBodyFieldsLength
and wired into the existing migration-scripts pipeline.

Verified: DynamicResourceDocTest, MigrationsTest, ResourceDocsTest,
SwaggerDocsTest and SwaggerFactoryUnitTest all pass; manually confirmed
the migration runs cleanly against a live Postgres instance and widens
the columns to text.
Class.getCanonicalName() returns null for a local or anonymous class.
A nested case class declared inside a runtime-compiled dynamic-endpoint
method body is exactly that from the JVM's perspective, so any example
body with a nested object (once the previous varchar(255) limit no
longer forces such examples to be omitted) crashed the entire
resource-docs listing with a NullPointerException, not just the
endpoint that declared the nested field.

Default to false (not an Option-typed field) when no canonical name is
available, matching Option's own canonical name always being present
since it is a top-level class.
…-body-length

fix: widen DynamicResourceDoc example/response body columns to text
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant