danielgtaylor / aglio

An API Blueprint renderer with theme support that outputs static HTML
4.75k stars 480 forks source link

nullable members weird rendering behaviour #313

Open CameronLonsdale opened 7 years ago

CameronLonsdale commented 7 years ago

I have the following data structures defined

### LocationStruct (object)
+ country: Australia (CountryStruct)
+ city: Sydney (string)
+ latitude (number, nullable)
+ longitude (number, nullable)

### CountryStruct (object)
+ name: Australia (string)
+ code (string, nullable)

And the use case for this data is the following

+ Request (application/json)
    + Attributes (LocationStruct)

This renders to the following JSON

{
  "country": {
    "name": "Australia",
    "code": "Hello, world!"
  },
  "city": "Sydney",
  "latitude": 1,
  "longitude": 1
}

I was expecting code, latitude and longitude to have the value null, as a sample value was not specified for them.

However, when I change the CountryStruct to be empty. eg.

### CountryStruct (object)

The following is rendered.

{
  "country": {},
  "city": "Sydney",
  "latitude": null,
  "longitude": null
}

Fairly strange behaviour. The functionality I'm looking for is to have the value null be rendered when no sample value is given to an objects member.

OrangeDog commented 7 years ago

Please sort this out. It's so infuriating that all optional members in the schema get instantiated as "Hello World!", 1, etc. instead of using the actual Body I have supplied.

See also http://stackoverflow.com/q/41986351/476716

stipsan commented 7 years ago

Here's the source of this behavior https://github.com/danielgtaylor/aglio/blob/olio-theme/src/example.coffee#L17

stipsan commented 7 years ago

Looks like you can disable it by setting DRAFTER_EXAMPLES=true. Like so: DRAFTER_EXAMPLES=true aglio -i apiary.apib.

optimuspaul commented 6 years ago

DRAFTER_EXAMPLES=true does nothing for me. Super frustrating as I was seeing the samples I put in the blueprints and now I only see the Hello, World! stuff.

brendensoares commented 5 years ago

@optimuspaul looks like #177 and #304 my be relevant. PR is sitting idle.