1

If I define a resource type with sample values, how can I override them for specific examples?

I tried this, but the rendered output ignores the Body and uses the global Sample instead.

### Read item [GET]
+ Response 200
    + Attributes (A, fixed-type)
    + Body

            { "name": "Hello", "bs": [{ "key": "value" }]}

# Data Structures
## A
+ name: foo(string, required)
+ bs (array[B], optional, fixed-type)
    + Sample
        + key: baz
        + key: bat
## B
+ key (string, optional)

Bizarrely, if you remove the sample values from the schema it correctly uses the Body for Request but for Response it has every string parameter as "Hello, world!", every number as 1, etc.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207

2 Answers2

2

if you use aglio and you get

string parameter as "Hello, world!", every number as 1

than use DRAFTER_EXAMPLES environment variable: DRAFTER_EXAMPLES=true aglio -i apiary.apib

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
Ilya Petukhov
  • 682
  • 7
  • 12
1

I know this is an old thread, but just came across this issue and wanted to elaborate on the above answer. In order to get this working, I had to set DRAFTER_EXAMPLES in the environment, and then execute the aglio command; for example:

set DRAFTER_EXAMPLES=true

aglio -i apiary.apib -o output.html
Muranamo
  • 11
  • 2
  • You should comment on an answer if you have something to add, not just post exactly the same thing, but with Windows CMD instead. – OrangeDog Dec 15 '18 at 17:57
  • I'll keep that in mind; although my post was not "exactly the same thing". The other answer indicates use of a DRAFTER_EXAMPLES parameter, not an environment variable. The important part is not the use of the set command, but rather that it clarifies the use of an environment variable, not a parameter. – Muranamo Dec 17 '18 at 05:10
  • No, the other answer is also using an environment variable, they just called it a parameter. – OrangeDog Dec 17 '18 at 08:14
  • A parameter and an environment variable are two completely different things. – Muranamo Dec 18 '18 at 17:33
  • Both answers are setting an environment variable – OrangeDog Dec 18 '18 at 17:34
  • Did you actually look at the edit? The command line is unchanged. All I did was change the ambiguous description "parameter" to "environment variable", because you seem to be confused about what an environment variable is. – OrangeDog Dec 19 '18 at 15:28
  • No, not ambiguous, they are two different things - you seem to think a parameter and an environment variable are the same thing. If you check the other threads on here and github you'll see that people are saying the original answer doesn't work, and that's probably because they're trying to use it as a parameter. I'm done with this thread. – Muranamo Dec 19 '18 at 15:33
  • I've worked with Linux for over a decade. The original answer did not use the Linux export command - it contained no information indicating that DRAFTER_EXAMPLES is to be set as an environment variable. Your statement regarding the command-line is also incorrect - an argument is the value (being passed in) of a parameter at runtime. This sort of pointless and invalid arguing seriously discourages people from contributing on here ... – Muranamo Dec 19 '18 at 16:01
  • I'm afraid you are wrong, despite how long you've been using Linux. Setting an environment variable and exporting an environment variable are different things. The line `KEY=VALUE command arg` runs `command` with the environment variable `KEY` set to `VALUE` and an argument of `arg`. Nothing there is called a "parameter". – OrangeDog Dec 19 '18 at 16:05
  • What you're referring to is a shell variable. That probably works too, but isn't universal. – Muranamo Dec 19 '18 at 16:19
  • No, it's setting an environment variable not a shell variable, and it works in every *NIX shell I've used. – OrangeDog Dec 19 '18 at 16:28