Git Product home page Git Product logo

Comments (5)

vanderlee avatar vanderlee commented on July 18, 2024

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.

weirdan avatar weirdan commented on July 18, 2024
  • object(typeA,propName:typeB) - would be parsed as object with propName of typeB and any additional properties of typeA (could be in any order, so object(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 brevity
  • object(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.

weirdan avatar weirdan commented on July 18, 2024

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.

weirdan avatar weirdan commented on July 18, 2024

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.

weirdan avatar weirdan commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.