fix(core): warn for dropped custom methods containing a dot (#24212)

Merged
KH
1d ago
+201-17

Follow-up to #24969 (issue #24212). That PR made CodegenConfigurator log a WARN naming each path-item member that swagger-parser rejects as attribute paths.'<path>'.<member> is unexpected, so operations under an HTTP method the parser does not know are no longer dropped silently. Its UNEXPECTED_PATH_ITEM_ATTRIBUTE pattern, however, excludes . from the member token, so a custom method whose name contains a dot is still dropped without that warning. RFC 9110 tchar allows . in method names (e.g. M.FOO).

Reproducer

modules/openapi-generator/src/test/resources/3_0/issue_24212_dotted_custom_method.yaml (added by this PR):

openapi: 3.0.3
info:
  title: issue 24212 dotted custom-method regression test
  version: '1.0'
paths:
  /tasks:
    get:
      operationId: getTasks
      responses:
        '200':
          description: OK
    M.FOO:
      operationId: mFooTasks
      responses:
        '200':
          description: OK
    m.foo:
      operationId: mFooLowerTasks
      responses:
        '200':
          description: OK

With --skip-validate-spec, swagger-parser reports attribute paths.'/tasks'.M.FOO is unexpected and attribute paths.'/tasks'.m.foo is unexpected, and the parsed /tasks path item keeps only get; the two custom methods are dropped. On master no MISSING warning is logged for M.FOO / m.foo, because ([^.\[\]()'\s]+) stops at the dot and the pattern does not match. With this PR both are reported, like any other dropped method.

Fix

  • CodegenConfigurator.UNEXPECTED_PATH_ITEM_ATTRIBUTE: the member group changes from [^.\[\]()'\s]+ to [^\[\]()'\s]+, so dots are allowed. The path group is unchanged.
  • Allowing dots must not turn nested typos into false MISSING warnings. I checked the messages swagger-parser 2.1.48 produces for typos below a path item:
    • inside an operation: paths.'/tasks'(get).responsses — the (get) segment is still rejected;
    • inside a path parameter: paths.'/tasks/{id}'.[id].requried — the [id] segment is still rejected;
    • inside a quoted member: paths.'/tasks'.'x-custom'.nested — the quote is still rejected;
    • inside a path-level server's variables: paths.'/tasks'.variables.env.descripton — this one has only dots. It always has the form variables.<name>.<field>, with a second dot after the variable name (also when the variable name itself contains a dot, e.g. variables.v2.x.descripton). The pattern therefore starts the member with the negative lookahead (?!variables\.[^.\[\]()'\s]+\.), which rejects exactly that shape. A custom method such as variables.foo has no second dot and is still reported.
  • The two existing no-false-positive tests keep passing, and a third one covers the variables case.

Test hardening

The #24212 tests capture CodegenConfigurator.LOGGER, which is a shared static logger, with a plain ListAppender. Surefire runs test classes in parallel (<parallel>classes</parallel> in the root pom.xml), so events that other threads log to the same logger could reach the list while a test reads it. This PR adds a helper that attaches a ListAppender with a filter keeping only the calling thread's events. The four existing #24212 tests and the new test use it, and shouldNotCaptureLogEventsFromOtherThreads checks the helper itself.

Tests

TestAsserts
shouldWarnAboutDroppedCustomMethodContainingDot (new)a WARN containing MISSING and naming 'M.FOO' at path '/tasks', 'm.foo' at path '/tasks' and 'variables.foo' at path '/tasks' is logged; get on /tasks is still present in the parsed spec
shouldNotFalsePositiveOnNestedServerVariableTypo (new)issue_24212_server_variable_typo.yaml: a typo inside a path-level server variable produces no MISSING warning
shouldNotCaptureLogEventsFromOtherThreads (new)the capturing appender ignores an event logged from another thread and keeps one logged from the test thread

./mvnw -nsu -Denforcer.skip=true -pl modules/openapi-generator -am -Dtest=CodegenConfiguratorTest -Dsurefire.failIfNoSpecifiedTests=false test

Tests runResult
master + this PR100 failures, 0 skipped
this PR with the CodegenConfigurator.java change reverted (tests kept)—shouldWarnAboutDroppedCustomMethodContainingDot fails
this PR with only the lookahead removed—shouldNotFalsePositiveOnNestedServerVariableTypo fails
this PR with the lookahead widened back to (?!variables\.)—shouldWarnAboutDroppedCustomMethodContainingDot fails on variables.foo

Scope

Logging only: no change to parsing, to the generated code, or to any sample. Every message that matched before still matches: the new character class is a superset of the old one, and the lookahead only rejects members that contain a dot, which the old pattern could not match.

cc @wing328

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples — not applicable beyond the build: the change only affects a log message, so no sample or generator doc output changes.
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. (Not applicable: this changes the generator core, not a single language; only the maintainer is cc'd above.)

🤖 Generated with Claude Code