Comments (5)
I love additionalProperties; they've been on top of my wishlist for a while now.
Just to get a clear idea of what you're trying to do. Would the following parse correctly?
object(type,propName:type)
object(propName:type,type,...)
object(propName:type,...)
object(...)
object(type,type)
object(type,...)
object(...,type) // I expect this should error?
As for the command form, wouldn't property type
or property ...
work, using variants of the current syntax for adding named properties to an object?
from phpswaggergen.
object(typeA,propName:typeB)
- would be parsed as object withpropName
oftypeB
and any additional properties oftypeA
(could be in any order, soobject(firstName:string,object,lastName:string)
would also be possible, meaning first and last names are strings, and anything else is an object)object(...)
- not sure what you mean here, you seem to imply literal ellipsis has some special meaning, while I was using ellipsis to signify there's some more named props in the example, omitted for brevityobject(type,type)
- that would be error, additional properties type defined twice
To give some more concrete examples:
function getCountries(): stdClass {
$ret = [];
$ret["count"] = 2;
$ret["UK"] = "Great Britain";
$ret["US"] = "The United States";
return (object) $ret;
}
would be documented/annotated to return this: object(string,count:integer)
, and
function getCustomer($id): CustomerDTO {
$ret = new CustomerDTO;
$ret->firstName = "John";
$ret->lastName = "Doe"
$ret->counts = (object) [
"total" => [1,2,3],
"current" => [2,3,4]
];
return $ret;
}
— like this:
model CustomerDTO object(firstName:string,lastName:string,counts:object(array(integer)))
using variants of the current syntax for adding named properties to an object?
Like, the same command but omitting the property name? That could work, but might lead to accidentally omitted prop name definition suddenly becoming the additional properties type definition. I'd prefer a separate command name.
from phpswaggergen.
might lead to accidentally omitted prop name definition suddenly becoming the additional properties type definition. I'd prefer a separate command name.
On the second thought though, it's what I actually propose for inline format, so it might make sense for consistency 😄
from phpswaggergen.
BTW, currently SG does not emit "additionalProperties" constraint for objects, which means any additional properties are valid ("additionalProperties": true
is implied by the spec, see p 5.4.4.3).
So if you thought about object(...)
allowing any additional properties, and object()
forbidding them, that would be a BC break. object(false,propName:propType)
could be a backward-compatible way to define 'strict' objects.
Alternatively, the syntax could be (here I use ellipsis literally, e.g. it will appear in annotations) object(...)
allowing any properties (equivalent to current object()
), object(...type)
allowing properties matching the type constraints and object(...!)
(or object(!...)
) disallowing additional properties.
from phpswaggergen.
Here's the current test for the syntax with ellipsis:
model IdModel object(id:uuid)
model AnyPropertiesAllowed object(...)
model AnyPropertiesAllowedCommand object
additionalproperties true
model TypedPropertiesAllowedInline object(...integer)
model TypedPropertiesAllowedCommand object
additionalproperties integer
model RefPropertiesAllowedInline object(...IdModel)
model RefPropertiesAllowedCommand object
additionalproperties IdModel
model NoAdditionalPropertiesAllowedInline object(propName:integer,...!)
model NoAdditionalPropertiesAllowedCommand object
property integer propName
additionalproperties false
model MixedPropertiesAndAdditionalPropertiesInline object(propName:integer,...)
model MixedPropertiesAndAdditionalPropertiesCommand object
property integer propName
additionalproperties true
model MixedPropertiesAndTypedAdditionalPropertiesInline object(propName:integer,...string)
model MixedPropertiesAndTypedAdditionalPropertiesCommand object
property integer propName
additionalproperties string
model MixedPropertiesAndRefAdditionaPropertiesInline object(propName:integer,...IdModel)
model MixedPropertiesAndRefAdditionalPropertiesCommand object
property integer propName
additionalproperties IdModel
Item starting with '...' would only be allowed once per prop-list, additionalproperties
command would only be allowed once for definition and would be disallowed if the item starting with '...' was seen during parsing of the inline definition.
from phpswaggergen.
Related Issues (19)
- Model inside a model support in response definition HOT 5
- Support for string:uuid HOT 9
- object(xxxx:array(),xxxxx:array()) throws exception HOT 4
- Property definitions should accept further (type-specific) commands HOT 1
- HEAD operation is not supported HOT 3
- Multiple definitions exist for class TestCase HOT 1
- @rest/require should create object on each item HOT 1
- Feature request for support example attribute for elements HOT 4
- Suppress 'exclusive(Max|Min)imum' for unbounded range ends
- Comments ignored with docblock (/**) syntax HOT 3
- Preserve EOL to be able to format description HOT 2
- Insert content of preprocessor variable into documentation
- Associative arrays are cast to objects, not arrays HOT 2
- PHP Parser fails when parsing @rest\property! HOT 1
- PHP 8 error: array and string offset access with curly braces HOT 2
- Default string value with spaces
- parsing error in the example of Swagger documentation HOT 1
- Duplicate properties and parameters are output twice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpswaggergen.