swagger-api / swagger-api/swagger-codegen
[PHP] Fix code example in README
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
This change accidentally broke code example in README https://github.com/swagger-api/swagger-codegen/commit/9ca9887de471fb82488592298e5e3e544f278aa7#diff-48c9b5ad08e2cc9e563b3ac9da839117
When using a Basic auth we get code example with non-working code. $config variable is missing and you will get fatal error because of applying ->setUsername('YOUR_USERNAME') to non-variable.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
{
"swagger" : "2.0",
"host": "example.com",
"schemes": [
"https"
],
"securityDefinitions": {
"basicAuth": {
"type": "basic"
}
},
"security": [
{"basicAuth": []}
],
"paths" : {
"/users/v3/orders" : {
"post" : {
"summary" : "Create a new order",
"description" : "To create a new order simply provide a JSON object with the applicable properties",
"operationId" : "createOrder",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "body",
"required" : false,
"schema" : {
"$ref" : "#/definitions/order"
}
} ],
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"$ref" : "#/definitions/order"
}
},
"400" : {
"description" : "We were unable to create an order with the provided data. Some field constraint was violated."
},
"401" : {
"description" : "You were not authorized to execute this operation."
}
},
"x-400" : {
"error_text" : "array|Bad value: order_amount|Bad value: order_tax_amount|Bad value: locale",
"correlation_id" : "1b4c6bfa-f182-43dd-bde0-6bec32as6cf0",
"error_code" : "BAD_VALUE"
}
}
}
},
"definitions" : {
"order_line" : {
"type" : "object",
"required" : [ "name", "quantity", "total_amount", "unit_price" ],
"properties" : {
"type" : {
"type" : "string",
"example" : "physical",
"position" : 1,
"description" : "Order line type. Possible values:<ul><li><em>physical</em></li><li><em>discount</em></li><li><em>shipping_fee</em></li><li><em>sales_tax</em></li><li><em>digital</em></li><li><em>gift_card</em></li><li><em>store_credit</em></li><li><em>surcharge</em></li></ul>"
},
"reference" : {
"type" : "string",
"example" : "19-402-USA",
"position" : 2,
"description" : "Article number, SKU or similar.",
"minLength" : 0,
"maxLength" : 64
},
"name" : {
"type" : "string",
"example" : "Red T-Shirt",
"position" : 3,
"description" : "Descriptive item name.",
"minLength" : 1,
"maxLength" : 255
},
"quantity" : {
"type" : "integer",
"format" : "int64",
"example" : 5,
"position" : 4,
"description" : "Non-negative. The item quantity.",
"minimum" : 0.0
},
"quantity_unit" : {
"type" : "string",
"example" : "pcs",
"position" : 5,
"description" : "Unit used to describe the quantity, e.g. kg, pcs... If defined has to be 1-8 characters"
},
"unit_price" : {
"type" : "integer",
"format" : "int64",
"example" : 10000,
"position" : 6,
"description" : "Minor units. Includes tax, excludes discount. (max value: 100000000)",
"maximum" : 1.0E8
},
"total_amount" : {
"type" : "integer",
"format" : "int64",
"example" : 50000,
"position" : 8,
"description" : "Includes tax and discount. Must match (quantity \\* unit_price) - total_discount_amount within ±quantity. (max value: 100000000)",
"maximum" : 1.0E8
},
"product_url" : {
"type" : "string",
"example" : "https://www.example.com/products/f2a8d7e34",
"position" : 12,
"description" : "URL to the product page that can be later embedded in communications between Klarna and the customer. (max 1024 characters)",
"minLength" : 0,
"maxLength" : 1024
},
"image_url" : {
"type" : "string",
"example" : "https://www.example.com/logo.png",
"position" : 13,
"description" : "URL to an image that can be later embedded in communications between Klarna and the customer. (max 1024 characters)",
"minLength" : 0,
"maxLength" : 1024
}
}
},
"order" : {
"type" : "object",
"required" : ["order_amount", "order_lines"],
"properties" : {
"order_id" : {
"type" : "string",
"example" : "f3392f8b-6116-4073-ab96-e330819e2c07",
"position" : 1,
"description" : "The unique order ID (max 255 characters).",
"readOnly" : true
},
"name" : {
"type" : "string",
"example" : "Women's Fashion",
"position" : 2,
"description" : "The merchant name (max 255 characters).",
"readOnly" : true
},
"status" : {
"type" : "string",
"example" : "CHECKOUT_INCOMPLETE",
"position" : 3,
"description" : "The current status of the order.",
"readOnly" : true
},
"billing_address" : {
"type" : "string",
"example" : "Germany, Berlin",
"position" : 4,
"description" : "Customer address"
},
"shipping_address" : {
"type" : "string",
"example" : "Germany, Berlin",
"position" : 5,
"description" : "Customer address"
},
"order_amount" : {
"type" : "integer",
"format" : "int64",
"example" : 50000,
"position" : 6,
"description" : "Non-negative, minor units. Total amount of the order, including tax and any discounts.",
"minimum" : 0.0
},
"order_lines" : {
"type" : "array",
"position" : 7,
"description" : "The applicable order lines (max 1000)",
"items" : {
"$ref" : "#/definitions/order_line"
},
"maxItems" : 1000,
"minItems" : 0
},
"started_at" : {
"type" : "string",
"format" : "date-time",
"position" : 8,
"description" : "ISO 8601 datetime. When the merchant created the order.",
"readOnly" : true
},
"completed_at" : {
"type" : "string",
"format" : "date-time",
"position" : 9,
"description" : "ISO 8601 datetime. When the customer completed the order.",
"readOnly" : true
},
"last_modified_at" : {
"type" : "string",
"format" : "date-time",
"position" : 10,
"description" : "ISO 8601 datetime. When the order was last modified.",
"readOnly" : true
}
}
}
}
}
Command line used for generation
swagger-codegen generate -i manifest.json -c config.json -l php -o sdk
Steps to reproduce
Nothing special. Just generate code using Basic auth description in manifest.
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/pull/7777
Suggest a fix/enhancement
NA
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the README and inspect the PHP Basic-auth example associated with commit 9ca9887de471fb82488592298e5e3e544f278aa7. Reproduce generation with the supplied manifest and command, then verify that the example defines $config before calling setUsername; completion means the generated README example no longer raises the reported fatal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100