Description
When a schema has default not in enum, multiple generators produce incorrect code (e.g., Python emits unquoted defaults causing NameError). This is technically valid JSON Schema but a common spec authoring mistake.
validate --recommend should warn per occurrence, e.g.:
Warnings:
- Schema has default value 'http' not in enum [udp]
openapi-generator version
master (7.22.0-SNAPSHOT)
OpenAPI declaration file content or url
openapi: "3.0.1"
info:
title: Test
version: "1.0"
paths: {}
components:
schemas:
Config:
type: object
properties:
protocol:
type: string
enum: [udp, tcp]
default: http
Command line used for generation
java -jar openapi-generator-cli.jar validate -i spec.yaml --recommend
Steps to reproduce
- Create a spec with a schema that has
default not in enum (as above)
- Run
validate --recommend
- No warning is produced about the mismatch
- Generate code (e.g., Python) — the generated default value is incorrect
Related issues/PRs
These are all downstream symptoms of the same root cause: specs with default ∉ enum that the validator doesn't catch.
Suggest a fix/enhancement
Add a validation rule in OpenApiEvaluator.validate() that iterates all schemas via a new ModelUtils.getAllSchemasInDocument() method (covering both component and inline path schemas) and warns when schema.getDefault() ∉ schema.getEnum(). Use the per-occurrence pattern (like unused schemas) so each occurrence gets its own warning message with the specific default value and enum list.
Description
When a schema has
defaultnot inenum, multiple generators produce incorrect code (e.g., Python emits unquoted defaults causingNameError). This is technically valid JSON Schema but a common spec authoring mistake.validate --recommendshould warn per occurrence, e.g.:openapi-generator version
master (7.22.0-SNAPSHOT)
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
defaultnot inenum(as above)validate --recommendRelated issues/PRs
These are all downstream symptoms of the same root cause: specs with
default ∉ enumthat the validator doesn't catch.Suggest a fix/enhancement
Add a validation rule in
OpenApiEvaluator.validate()that iterates all schemas via a newModelUtils.getAllSchemasInDocument()method (covering both component and inline path schemas) and warns whenschema.getDefault() ∉ schema.getEnum(). Use the per-occurrence pattern (like unused schemas) so each occurrence gets its own warning message with the specific default value and enum list.