[Bug]: Anonymous objects fail to report errors during parsing
Description
The below Swagger doc passes through the SwaggerParser without generating any error messages. The same doc opened in various code editors [including editor.swagger.io] highlights the issue with the lack of object name. In addition, duplicate object names do not seem to be parsed so setting both objects to a name of "" overwrites the first definition with the second silently - "" being a valid string in Java, even if not valid according to the Swagger spec.
Affected Version
1.0.71 Also using SwaggerConvertor and 2.1.22, the converted doc doesn't flag an issue.
Steps to Reproduce
{
"swagger": "2.0",
"info": {
"title": "info_title",
"version": "0/0",
"description": "..",
"contact": {
"name": "contactname",
"url": "contacturl",
"email": "[email protected]"
}
},
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"basePath": "/basepath",
"paths": {
"/path": {
"get": {
"summary": "summary",
"responses": {
"200": {
"description": "..",
"schema": {
"type": "object",
"properties": {
"AA": {
"type": "string"
},
"": {
"type": "number"
}
}
}
}
},
"operationId": "getopid",
"description": ".."
}
}
}
}
Expected Behavior
Error messages similar to those from editor.swagger.io:
properties members must be schemasapilint(10037)
properties: object
The value of "properties" MUST be an object. Each value of this object MUST be a valid JSON Schema.
Actual Behavior
Document parsed successfully; attempts to reference the "anonymous" fields cause further processing issues
Environment
- Java version: various
- Build tool: maven
- OS: Fedora 43
Checklist
- [x] I have searched the existing issues and this is not a duplicate.
- [x] I have provided sufficient information for maintainers to reproduce the issue.
Hi, I looked into this and was able to reproduce the behavior.
I have a small fix ready that adds a validation message when a Swagger 2.0 schema contains an empty property name under properties, along with a regression test based on the example from this issue.
I’ll open a PR for review.
Thanks for the report and the reproducer @DevonianTeuchter!
An empty key in properties isn't prohibited by Swagger 2.0.
The OpenAPI 2.0 Schema Object applies JSON Schema semantics to properties. JSON Schema Draft 4 requires properties to be an object where each value is a valid schema, but says nothing about the names being non-empty. The official OpenAPI 2.0 validation schema has no such restriction either.
The editor diagnostic you quoted is about the values inside properties, not the keys. It says each value must be a schema. It says nothing about property names being non-empty.
JSON works the same way. RFC 8259 defines member names as strings, and section 7 allows strings with zero or more characters, so "" is a valid member name.
Duplicate names are a separate concern. RFC 8259 recommends unique names and warns that behavior is unpredictable when names repeat; many parsers keep only one value. Detecting duplicates reliably would need to happen at parse time, before the data lands in a Java Map.
Since an empty property name is consistent with Swagger 2.0, we're closing this issue as reported.
Handling duplicate members would need parser-level detection and a decision about whether to make strict checking optional or on by default. If there's interest in that, it should be a separate enhancement request.
Empty-name rejection should be an optional lint rule, not a Swagger 2.0 validation constraint.