mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Use vendored go-swagger (#8087)
* Use vendored go-swagger * vendor go-swagger * revert un wanteed change * remove un-needed GO111MODULE * Update Makefile Co-Authored-By: techknowlogick <matti@mdranta.net>
This commit is contained in:
		 Antoine GIRARD
					Antoine GIRARD
				
			
				
					committed by
					
						 Lauris BH
						Lauris BH
					
				
			
			
				
	
			
			
			 Lauris BH
						Lauris BH
					
				
			
						parent
						
							4cb1bdddc8
						
					
				
				
					commit
					9fe4437bda
				
			
							
								
								
									
										5
									
								
								vendor/github.com/go-openapi/analysis/.codecov.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/go-openapi/analysis/.codecov.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| coverage: | ||||
|   status: | ||||
|     patch: | ||||
|       default: | ||||
|         target: 80% | ||||
							
								
								
									
										5
									
								
								vendor/github.com/go-openapi/analysis/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/go-openapi/analysis/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| secrets.yml | ||||
| coverage.out | ||||
| coverage.txt | ||||
| *.cov | ||||
| .idea | ||||
							
								
								
									
										27
									
								
								vendor/github.com/go-openapi/analysis/.golangci.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								vendor/github.com/go-openapi/analysis/.golangci.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| linters-settings: | ||||
|   govet: | ||||
|     check-shadowing: true | ||||
|   golint: | ||||
|     min-confidence: 0 | ||||
|   gocyclo: | ||||
|     min-complexity: 40 | ||||
|   maligned: | ||||
|     suggest-new: true | ||||
|   dupl: | ||||
|     threshold: 100 | ||||
|   goconst: | ||||
|     min-len: 2 | ||||
|     min-occurrences: 4 | ||||
|  | ||||
| linters: | ||||
|   enable-all: true | ||||
|   disable: | ||||
|     - maligned | ||||
|     - lll | ||||
|     - gochecknoglobals | ||||
|     - gochecknoinits | ||||
|     # scopelint is useful, but also reports false positives | ||||
|     # that unfortunately can't be disabled. So we disable the | ||||
|     # linter rather than changing code that works. | ||||
|     # see: https://github.com/kyoh86/scopelint/issues/4 | ||||
|     - scopelint | ||||
							
								
								
									
										15
									
								
								vendor/github.com/go-openapi/analysis/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								vendor/github.com/go-openapi/analysis/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| after_success: | ||||
| - bash <(curl -s https://codecov.io/bash) | ||||
| go: | ||||
| - 1.11.x | ||||
| - 1.12.x | ||||
| install: | ||||
| - GO111MODULE=off go get -u gotest.tools/gotestsum | ||||
| env: | ||||
| - GO111MODULE=on | ||||
| language: go | ||||
| notifications: | ||||
|   slack: | ||||
|     secure: Sf7kZf7ZGbnwWUMpffHwMu5A0cHkLK2MYY32LNTPj4+/3qC3Ghl7+9v4TSLOqOlCwdRNjOGblAq7s+GDJed6/xgRQl1JtCi1klzZNrYX4q01pgTPvvGcwbBkIYgeMaPeIRcK9OZnud7sRXdttozgTOpytps2U6Js32ip7uj5mHSg2ub0FwoSJwlS6dbezZ8+eDhoha0F/guY99BEwx8Bd+zROrT2TFGsSGOFGN6wFc7moCqTHO/YkWib13a2QNXqOxCCVBy/lt76Wp+JkeFppjHlzs/2lP3EAk13RIUAaesdEUHvIHrzCyNJEd3/+KO2DzsWOYfpktd+KBCvgaYOsoo7ubdT3IROeAegZdCgo/6xgCEsmFc9ZcqCfN5yNx2A+BZ2Vwmpws+bQ1E1+B5HDzzaiLcYfG4X2O210QVGVDLWsv1jqD+uPYeHY2WRfh5ZsIUFvaqgUEnwHwrK44/8REAhQavt1QAj5uJpsRd7CkRVPWRNK+yIky+wgbVUFEchRNmS55E7QWf+W4+4QZkQi7vUTMc9nbTUu2Es9NfvfudOpM2wZbn98fjpb/qq/nRv6Bk+ca+7XD5/IgNLMbWp2ouDdzbiHLCOfDUiHiDJhLfFZx9Bwo7ZwfzeOlbrQX66bx7xRKYmOe4DLrXhNcpbsMa8qbfxlZRCmYbubB/Y8h4= | ||||
| script: | ||||
| - gotestsum -f short-verbose -- -race -timeout=20m -coverprofile=coverage.txt -covermode=atomic ./... | ||||
							
								
								
									
										74
									
								
								vendor/github.com/go-openapi/analysis/CODE_OF_CONDUCT.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/go-openapi/analysis/CODE_OF_CONDUCT.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| # Contributor Covenant Code of Conduct | ||||
|  | ||||
| ## Our Pledge | ||||
|  | ||||
| In the interest of fostering an open and welcoming environment, we as | ||||
| contributors and maintainers pledge to making participation in our project and | ||||
| our community a harassment-free experience for everyone, regardless of age, body | ||||
| size, disability, ethnicity, gender identity and expression, level of experience, | ||||
| nationality, personal appearance, race, religion, or sexual identity and | ||||
| orientation. | ||||
|  | ||||
| ## Our Standards | ||||
|  | ||||
| Examples of behavior that contributes to creating a positive environment | ||||
| include: | ||||
|  | ||||
| * Using welcoming and inclusive language | ||||
| * Being respectful of differing viewpoints and experiences | ||||
| * Gracefully accepting constructive criticism | ||||
| * Focusing on what is best for the community | ||||
| * Showing empathy towards other community members | ||||
|  | ||||
| Examples of unacceptable behavior by participants include: | ||||
|  | ||||
| * The use of sexualized language or imagery and unwelcome sexual attention or | ||||
| advances | ||||
| * Trolling, insulting/derogatory comments, and personal or political attacks | ||||
| * Public or private harassment | ||||
| * Publishing others' private information, such as a physical or electronic | ||||
|   address, without explicit permission | ||||
| * Other conduct which could reasonably be considered inappropriate in a | ||||
|   professional setting | ||||
|  | ||||
| ## Our Responsibilities | ||||
|  | ||||
| Project maintainers are responsible for clarifying the standards of acceptable | ||||
| behavior and are expected to take appropriate and fair corrective action in | ||||
| response to any instances of unacceptable behavior. | ||||
|  | ||||
| Project maintainers have the right and responsibility to remove, edit, or | ||||
| reject comments, commits, code, wiki edits, issues, and other contributions | ||||
| that are not aligned to this Code of Conduct, or to ban temporarily or | ||||
| permanently any contributor for other behaviors that they deem inappropriate, | ||||
| threatening, offensive, or harmful. | ||||
|  | ||||
| ## Scope | ||||
|  | ||||
| This Code of Conduct applies both within project spaces and in public spaces | ||||
| when an individual is representing the project or its community. Examples of | ||||
| representing a project or community include using an official project e-mail | ||||
| address, posting via an official social media account, or acting as an appointed | ||||
| representative at an online or offline event. Representation of a project may be | ||||
| further defined and clarified by project maintainers. | ||||
|  | ||||
| ## Enforcement | ||||
|  | ||||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||||
| reported by contacting the project team at ivan+abuse@flanders.co.nz. All | ||||
| complaints will be reviewed and investigated and will result in a response that | ||||
| is deemed necessary and appropriate to the circumstances. The project team is | ||||
| obligated to maintain confidentiality with regard to the reporter of an incident. | ||||
| Further details of specific enforcement policies may be posted separately. | ||||
|  | ||||
| Project maintainers who do not follow or enforce the Code of Conduct in good | ||||
| faith may face temporary or permanent repercussions as determined by other | ||||
| members of the project's leadership. | ||||
|  | ||||
| ## Attribution | ||||
|  | ||||
| This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||||
| available at [http://contributor-covenant.org/version/1/4][version] | ||||
|  | ||||
| [homepage]: http://contributor-covenant.org | ||||
| [version]: http://contributor-covenant.org/version/1/4/ | ||||
							
								
								
									
										202
									
								
								vendor/github.com/go-openapi/analysis/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								vendor/github.com/go-openapi/analysis/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,202 @@ | ||||
|  | ||||
|                                  Apache License | ||||
|                            Version 2.0, January 2004 | ||||
|                         http://www.apache.org/licenses/ | ||||
|  | ||||
|    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||||
|  | ||||
|    1. Definitions. | ||||
|  | ||||
|       "License" shall mean the terms and conditions for use, reproduction, | ||||
|       and distribution as defined by Sections 1 through 9 of this document. | ||||
|  | ||||
|       "Licensor" shall mean the copyright owner or entity authorized by | ||||
|       the copyright owner that is granting the License. | ||||
|  | ||||
|       "Legal Entity" shall mean the union of the acting entity and all | ||||
|       other entities that control, are controlled by, or are under common | ||||
|       control with that entity. For the purposes of this definition, | ||||
|       "control" means (i) the power, direct or indirect, to cause the | ||||
|       direction or management of such entity, whether by contract or | ||||
|       otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||||
|       outstanding shares, or (iii) beneficial ownership of such entity. | ||||
|  | ||||
|       "You" (or "Your") shall mean an individual or Legal Entity | ||||
|       exercising permissions granted by this License. | ||||
|  | ||||
|       "Source" form shall mean the preferred form for making modifications, | ||||
|       including but not limited to software source code, documentation | ||||
|       source, and configuration files. | ||||
|  | ||||
|       "Object" form shall mean any form resulting from mechanical | ||||
|       transformation or translation of a Source form, including but | ||||
|       not limited to compiled object code, generated documentation, | ||||
|       and conversions to other media types. | ||||
|  | ||||
|       "Work" shall mean the work of authorship, whether in Source or | ||||
|       Object form, made available under the License, as indicated by a | ||||
|       copyright notice that is included in or attached to the work | ||||
|       (an example is provided in the Appendix below). | ||||
|  | ||||
|       "Derivative Works" shall mean any work, whether in Source or Object | ||||
|       form, that is based on (or derived from) the Work and for which the | ||||
|       editorial revisions, annotations, elaborations, or other modifications | ||||
|       represent, as a whole, an original work of authorship. For the purposes | ||||
|       of this License, Derivative Works shall not include works that remain | ||||
|       separable from, or merely link (or bind by name) to the interfaces of, | ||||
|       the Work and Derivative Works thereof. | ||||
|  | ||||
|       "Contribution" shall mean any work of authorship, including | ||||
|       the original version of the Work and any modifications or additions | ||||
|       to that Work or Derivative Works thereof, that is intentionally | ||||
|       submitted to Licensor for inclusion in the Work by the copyright owner | ||||
|       or by an individual or Legal Entity authorized to submit on behalf of | ||||
|       the copyright owner. For the purposes of this definition, "submitted" | ||||
|       means any form of electronic, verbal, or written communication sent | ||||
|       to the Licensor or its representatives, including but not limited to | ||||
|       communication on electronic mailing lists, source code control systems, | ||||
|       and issue tracking systems that are managed by, or on behalf of, the | ||||
|       Licensor for the purpose of discussing and improving the Work, but | ||||
|       excluding communication that is conspicuously marked or otherwise | ||||
|       designated in writing by the copyright owner as "Not a Contribution." | ||||
|  | ||||
|       "Contributor" shall mean Licensor and any individual or Legal Entity | ||||
|       on behalf of whom a Contribution has been received by Licensor and | ||||
|       subsequently incorporated within the Work. | ||||
|  | ||||
|    2. Grant of Copyright License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       copyright license to reproduce, prepare Derivative Works of, | ||||
|       publicly display, publicly perform, sublicense, and distribute the | ||||
|       Work and such Derivative Works in Source or Object form. | ||||
|  | ||||
|    3. Grant of Patent License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       (except as stated in this section) patent license to make, have made, | ||||
|       use, offer to sell, sell, import, and otherwise transfer the Work, | ||||
|       where such license applies only to those patent claims licensable | ||||
|       by such Contributor that are necessarily infringed by their | ||||
|       Contribution(s) alone or by combination of their Contribution(s) | ||||
|       with the Work to which such Contribution(s) was submitted. If You | ||||
|       institute patent litigation against any entity (including a | ||||
|       cross-claim or counterclaim in a lawsuit) alleging that the Work | ||||
|       or a Contribution incorporated within the Work constitutes direct | ||||
|       or contributory patent infringement, then any patent licenses | ||||
|       granted to You under this License for that Work shall terminate | ||||
|       as of the date such litigation is filed. | ||||
|  | ||||
|    4. Redistribution. You may reproduce and distribute copies of the | ||||
|       Work or Derivative Works thereof in any medium, with or without | ||||
|       modifications, and in Source or Object form, provided that You | ||||
|       meet the following conditions: | ||||
|  | ||||
|       (a) You must give any other recipients of the Work or | ||||
|           Derivative Works a copy of this License; and | ||||
|  | ||||
|       (b) You must cause any modified files to carry prominent notices | ||||
|           stating that You changed the files; and | ||||
|  | ||||
|       (c) You must retain, in the Source form of any Derivative Works | ||||
|           that You distribute, all copyright, patent, trademark, and | ||||
|           attribution notices from the Source form of the Work, | ||||
|           excluding those notices that do not pertain to any part of | ||||
|           the Derivative Works; and | ||||
|  | ||||
|       (d) If the Work includes a "NOTICE" text file as part of its | ||||
|           distribution, then any Derivative Works that You distribute must | ||||
|           include a readable copy of the attribution notices contained | ||||
|           within such NOTICE file, excluding those notices that do not | ||||
|           pertain to any part of the Derivative Works, in at least one | ||||
|           of the following places: within a NOTICE text file distributed | ||||
|           as part of the Derivative Works; within the Source form or | ||||
|           documentation, if provided along with the Derivative Works; or, | ||||
|           within a display generated by the Derivative Works, if and | ||||
|           wherever such third-party notices normally appear. The contents | ||||
|           of the NOTICE file are for informational purposes only and | ||||
|           do not modify the License. You may add Your own attribution | ||||
|           notices within Derivative Works that You distribute, alongside | ||||
|           or as an addendum to the NOTICE text from the Work, provided | ||||
|           that such additional attribution notices cannot be construed | ||||
|           as modifying the License. | ||||
|  | ||||
|       You may add Your own copyright statement to Your modifications and | ||||
|       may provide additional or different license terms and conditions | ||||
|       for use, reproduction, or distribution of Your modifications, or | ||||
|       for any such Derivative Works as a whole, provided Your use, | ||||
|       reproduction, and distribution of the Work otherwise complies with | ||||
|       the conditions stated in this License. | ||||
|  | ||||
|    5. Submission of Contributions. Unless You explicitly state otherwise, | ||||
|       any Contribution intentionally submitted for inclusion in the Work | ||||
|       by You to the Licensor shall be under the terms and conditions of | ||||
|       this License, without any additional terms or conditions. | ||||
|       Notwithstanding the above, nothing herein shall supersede or modify | ||||
|       the terms of any separate license agreement you may have executed | ||||
|       with Licensor regarding such Contributions. | ||||
|  | ||||
|    6. Trademarks. This License does not grant permission to use the trade | ||||
|       names, trademarks, service marks, or product names of the Licensor, | ||||
|       except as required for reasonable and customary use in describing the | ||||
|       origin of the Work and reproducing the content of the NOTICE file. | ||||
|  | ||||
|    7. Disclaimer of Warranty. Unless required by applicable law or | ||||
|       agreed to in writing, Licensor provides the Work (and each | ||||
|       Contributor provides its Contributions) on an "AS IS" BASIS, | ||||
|       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||
|       implied, including, without limitation, any warranties or conditions | ||||
|       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||||
|       PARTICULAR PURPOSE. You are solely responsible for determining the | ||||
|       appropriateness of using or redistributing the Work and assume any | ||||
|       risks associated with Your exercise of permissions under this License. | ||||
|  | ||||
|    8. Limitation of Liability. In no event and under no legal theory, | ||||
|       whether in tort (including negligence), contract, or otherwise, | ||||
|       unless required by applicable law (such as deliberate and grossly | ||||
|       negligent acts) or agreed to in writing, shall any Contributor be | ||||
|       liable to You for damages, including any direct, indirect, special, | ||||
|       incidental, or consequential damages of any character arising as a | ||||
|       result of this License or out of the use or inability to use the | ||||
|       Work (including but not limited to damages for loss of goodwill, | ||||
|       work stoppage, computer failure or malfunction, or any and all | ||||
|       other commercial damages or losses), even if such Contributor | ||||
|       has been advised of the possibility of such damages. | ||||
|  | ||||
|    9. Accepting Warranty or Additional Liability. While redistributing | ||||
|       the Work or Derivative Works thereof, You may choose to offer, | ||||
|       and charge a fee for, acceptance of support, warranty, indemnity, | ||||
|       or other liability obligations and/or rights consistent with this | ||||
|       License. However, in accepting such obligations, You may act only | ||||
|       on Your own behalf and on Your sole responsibility, not on behalf | ||||
|       of any other Contributor, and only if You agree to indemnify, | ||||
|       defend, and hold each Contributor harmless for any liability | ||||
|       incurred by, or claims asserted against, such Contributor by reason | ||||
|       of your accepting any such warranty or additional liability. | ||||
|  | ||||
|    END OF TERMS AND CONDITIONS | ||||
|  | ||||
|    APPENDIX: How to apply the Apache License to your work. | ||||
|  | ||||
|       To apply the Apache License to your work, attach the following | ||||
|       boilerplate notice, with the fields enclosed by brackets "[]" | ||||
|       replaced with your own identifying information. (Don't include | ||||
|       the brackets!)  The text should be enclosed in the appropriate | ||||
|       comment syntax for the file format. We also recommend that a | ||||
|       file or class name and description of purpose be included on the | ||||
|       same "printed page" as the copyright notice for easier | ||||
|       identification within third-party archives. | ||||
|  | ||||
|    Copyright [yyyy] [name of copyright owner] | ||||
|  | ||||
|    Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|    you may not use this file except in compliance with the License. | ||||
|    You may obtain a copy of the License at | ||||
|  | ||||
|        http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  | ||||
|    Unless required by applicable law or agreed to in writing, software | ||||
|    distributed under the License is distributed on an "AS IS" BASIS, | ||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|    See the License for the specific language governing permissions and | ||||
|    limitations under the License. | ||||
							
								
								
									
										9
									
								
								vendor/github.com/go-openapi/analysis/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/go-openapi/analysis/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # OpenAPI initiative analysis [](https://travis-ci.org/go-openapi/analysis) [](https://codecov.io/gh/go-openapi/analysis) [](https://slackin.goswagger.io) | ||||
|  | ||||
| [](https://raw.githubusercontent.com/go-openapi/analysis/master/LICENSE) | ||||
| [](http://godoc.org/github.com/go-openapi/analysis) | ||||
| [](https://golangci.com) | ||||
| [](https://goreportcard.com/report/github.com/go-openapi/analysis) | ||||
|  | ||||
|  | ||||
| A foundational library to analyze an OAI specification document for easier reasoning about the content. | ||||
							
								
								
									
										970
									
								
								vendor/github.com/go-openapi/analysis/analyzer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										970
									
								
								vendor/github.com/go-openapi/analysis/analyzer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,970 @@ | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package analysis | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	slashpath "path" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/go-openapi/jsonpointer" | ||||
| 	"github.com/go-openapi/spec" | ||||
| 	"github.com/go-openapi/swag" | ||||
| ) | ||||
|  | ||||
| type referenceAnalysis struct { | ||||
| 	schemas        map[string]spec.Ref | ||||
| 	responses      map[string]spec.Ref | ||||
| 	parameters     map[string]spec.Ref | ||||
| 	items          map[string]spec.Ref | ||||
| 	headerItems    map[string]spec.Ref | ||||
| 	parameterItems map[string]spec.Ref | ||||
| 	allRefs        map[string]spec.Ref | ||||
| 	pathItems      map[string]spec.Ref | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addRef(key string, ref spec.Ref) { | ||||
| 	r.allRefs["#"+key] = ref | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addItemsRef(key string, items *spec.Items, location string) { | ||||
| 	r.items["#"+key] = items.Ref | ||||
| 	r.addRef(key, items.Ref) | ||||
| 	if location == "header" { | ||||
| 		// NOTE: in swagger 2.0, headers and parameters (but not body param schemas) are simple schemas | ||||
| 		// and $ref are not supported here. However it is possible to analyze this. | ||||
| 		r.headerItems["#"+key] = items.Ref | ||||
| 	} else { | ||||
| 		r.parameterItems["#"+key] = items.Ref | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addSchemaRef(key string, ref SchemaRef) { | ||||
| 	r.schemas["#"+key] = ref.Schema.Ref | ||||
| 	r.addRef(key, ref.Schema.Ref) | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addResponseRef(key string, resp *spec.Response) { | ||||
| 	r.responses["#"+key] = resp.Ref | ||||
| 	r.addRef(key, resp.Ref) | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addParamRef(key string, param *spec.Parameter) { | ||||
| 	r.parameters["#"+key] = param.Ref | ||||
| 	r.addRef(key, param.Ref) | ||||
| } | ||||
|  | ||||
| func (r *referenceAnalysis) addPathItemRef(key string, pathItem *spec.PathItem) { | ||||
| 	r.pathItems["#"+key] = pathItem.Ref | ||||
| 	r.addRef(key, pathItem.Ref) | ||||
| } | ||||
|  | ||||
| type patternAnalysis struct { | ||||
| 	parameters  map[string]string | ||||
| 	headers     map[string]string | ||||
| 	items       map[string]string | ||||
| 	schemas     map[string]string | ||||
| 	allPatterns map[string]string | ||||
| } | ||||
|  | ||||
| func (p *patternAnalysis) addPattern(key, pattern string) { | ||||
| 	p.allPatterns["#"+key] = pattern | ||||
| } | ||||
|  | ||||
| func (p *patternAnalysis) addParameterPattern(key, pattern string) { | ||||
| 	p.parameters["#"+key] = pattern | ||||
| 	p.addPattern(key, pattern) | ||||
| } | ||||
|  | ||||
| func (p *patternAnalysis) addHeaderPattern(key, pattern string) { | ||||
| 	p.headers["#"+key] = pattern | ||||
| 	p.addPattern(key, pattern) | ||||
| } | ||||
|  | ||||
| func (p *patternAnalysis) addItemsPattern(key, pattern string) { | ||||
| 	p.items["#"+key] = pattern | ||||
| 	p.addPattern(key, pattern) | ||||
| } | ||||
|  | ||||
| func (p *patternAnalysis) addSchemaPattern(key, pattern string) { | ||||
| 	p.schemas["#"+key] = pattern | ||||
| 	p.addPattern(key, pattern) | ||||
| } | ||||
|  | ||||
| type enumAnalysis struct { | ||||
| 	parameters map[string][]interface{} | ||||
| 	headers    map[string][]interface{} | ||||
| 	items      map[string][]interface{} | ||||
| 	schemas    map[string][]interface{} | ||||
| 	allEnums   map[string][]interface{} | ||||
| } | ||||
|  | ||||
| func (p *enumAnalysis) addEnum(key string, enum []interface{}) { | ||||
| 	p.allEnums["#"+key] = enum | ||||
| } | ||||
|  | ||||
| func (p *enumAnalysis) addParameterEnum(key string, enum []interface{}) { | ||||
| 	p.parameters["#"+key] = enum | ||||
| 	p.addEnum(key, enum) | ||||
| } | ||||
|  | ||||
| func (p *enumAnalysis) addHeaderEnum(key string, enum []interface{}) { | ||||
| 	p.headers["#"+key] = enum | ||||
| 	p.addEnum(key, enum) | ||||
| } | ||||
|  | ||||
| func (p *enumAnalysis) addItemsEnum(key string, enum []interface{}) { | ||||
| 	p.items["#"+key] = enum | ||||
| 	p.addEnum(key, enum) | ||||
| } | ||||
|  | ||||
| func (p *enumAnalysis) addSchemaEnum(key string, enum []interface{}) { | ||||
| 	p.schemas["#"+key] = enum | ||||
| 	p.addEnum(key, enum) | ||||
| } | ||||
|  | ||||
| // New takes a swagger spec object and returns an analyzed spec document. | ||||
| // The analyzed document contains a number of indices that make it easier to | ||||
| // reason about semantics of a swagger specification for use in code generation | ||||
| // or validation etc. | ||||
| func New(doc *spec.Swagger) *Spec { | ||||
| 	a := &Spec{ | ||||
| 		spec:       doc, | ||||
| 		references: referenceAnalysis{}, | ||||
| 		patterns:   patternAnalysis{}, | ||||
| 		enums:      enumAnalysis{}, | ||||
| 	} | ||||
| 	a.reset() | ||||
| 	a.initialize() | ||||
| 	return a | ||||
| } | ||||
|  | ||||
| // Spec is an analyzed specification object. It takes a swagger spec object and turns it into a registry | ||||
| // with a bunch of utility methods to act on the information in the spec. | ||||
| type Spec struct { | ||||
| 	spec        *spec.Swagger | ||||
| 	consumes    map[string]struct{} | ||||
| 	produces    map[string]struct{} | ||||
| 	authSchemes map[string]struct{} | ||||
| 	operations  map[string]map[string]*spec.Operation | ||||
| 	references  referenceAnalysis | ||||
| 	patterns    patternAnalysis | ||||
| 	enums       enumAnalysis | ||||
| 	allSchemas  map[string]SchemaRef | ||||
| 	allOfs      map[string]SchemaRef | ||||
| } | ||||
|  | ||||
| func (s *Spec) reset() { | ||||
| 	s.consumes = make(map[string]struct{}, 150) | ||||
| 	s.produces = make(map[string]struct{}, 150) | ||||
| 	s.authSchemes = make(map[string]struct{}, 150) | ||||
| 	s.operations = make(map[string]map[string]*spec.Operation, 150) | ||||
| 	s.allSchemas = make(map[string]SchemaRef, 150) | ||||
| 	s.allOfs = make(map[string]SchemaRef, 150) | ||||
| 	s.references.schemas = make(map[string]spec.Ref, 150) | ||||
| 	s.references.pathItems = make(map[string]spec.Ref, 150) | ||||
| 	s.references.responses = make(map[string]spec.Ref, 150) | ||||
| 	s.references.parameters = make(map[string]spec.Ref, 150) | ||||
| 	s.references.items = make(map[string]spec.Ref, 150) | ||||
| 	s.references.headerItems = make(map[string]spec.Ref, 150) | ||||
| 	s.references.parameterItems = make(map[string]spec.Ref, 150) | ||||
| 	s.references.allRefs = make(map[string]spec.Ref, 150) | ||||
| 	s.patterns.parameters = make(map[string]string, 150) | ||||
| 	s.patterns.headers = make(map[string]string, 150) | ||||
| 	s.patterns.items = make(map[string]string, 150) | ||||
| 	s.patterns.schemas = make(map[string]string, 150) | ||||
| 	s.patterns.allPatterns = make(map[string]string, 150) | ||||
| 	s.enums.parameters = make(map[string][]interface{}, 150) | ||||
| 	s.enums.headers = make(map[string][]interface{}, 150) | ||||
| 	s.enums.items = make(map[string][]interface{}, 150) | ||||
| 	s.enums.schemas = make(map[string][]interface{}, 150) | ||||
| 	s.enums.allEnums = make(map[string][]interface{}, 150) | ||||
| } | ||||
|  | ||||
| func (s *Spec) reload() { | ||||
| 	s.reset() | ||||
| 	s.initialize() | ||||
| } | ||||
|  | ||||
| func (s *Spec) initialize() { | ||||
| 	for _, c := range s.spec.Consumes { | ||||
| 		s.consumes[c] = struct{}{} | ||||
| 	} | ||||
| 	for _, c := range s.spec.Produces { | ||||
| 		s.produces[c] = struct{}{} | ||||
| 	} | ||||
| 	for _, ss := range s.spec.Security { | ||||
| 		for k := range ss { | ||||
| 			s.authSchemes[k] = struct{}{} | ||||
| 		} | ||||
| 	} | ||||
| 	for path, pathItem := range s.AllPaths() { | ||||
| 		s.analyzeOperations(path, &pathItem) | ||||
| 	} | ||||
|  | ||||
| 	for name, parameter := range s.spec.Parameters { | ||||
| 		refPref := slashpath.Join("/parameters", jsonpointer.Escape(name)) | ||||
| 		if parameter.Items != nil { | ||||
| 			s.analyzeItems("items", parameter.Items, refPref, "parameter") | ||||
| 		} | ||||
| 		if parameter.In == "body" && parameter.Schema != nil { | ||||
| 			s.analyzeSchema("schema", *parameter.Schema, refPref) | ||||
| 		} | ||||
| 		if parameter.Pattern != "" { | ||||
| 			s.patterns.addParameterPattern(refPref, parameter.Pattern) | ||||
| 		} | ||||
| 		if len(parameter.Enum) > 0 { | ||||
| 			s.enums.addParameterEnum(refPref, parameter.Enum) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for name, response := range s.spec.Responses { | ||||
| 		refPref := slashpath.Join("/responses", jsonpointer.Escape(name)) | ||||
| 		for k, v := range response.Headers { | ||||
| 			hRefPref := slashpath.Join(refPref, "headers", k) | ||||
| 			if v.Items != nil { | ||||
| 				s.analyzeItems("items", v.Items, hRefPref, "header") | ||||
| 			} | ||||
| 			if v.Pattern != "" { | ||||
| 				s.patterns.addHeaderPattern(hRefPref, v.Pattern) | ||||
| 			} | ||||
| 			if len(v.Enum) > 0 { | ||||
| 				s.enums.addHeaderEnum(hRefPref, v.Enum) | ||||
| 			} | ||||
| 		} | ||||
| 		if response.Schema != nil { | ||||
| 			s.analyzeSchema("schema", *response.Schema, refPref) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for name, schema := range s.spec.Definitions { | ||||
| 		s.analyzeSchema(name, schema, "/definitions") | ||||
| 	} | ||||
| 	// TODO: after analyzing all things and flattening schemas etc | ||||
| 	// resolve all the collected references to their final representations | ||||
| 	// best put in a separate method because this could get expensive | ||||
| } | ||||
|  | ||||
| func (s *Spec) analyzeOperations(path string, pi *spec.PathItem) { | ||||
| 	// TODO: resolve refs here? | ||||
| 	// Currently, operations declared via pathItem $ref are known only after expansion | ||||
| 	op := pi | ||||
| 	if pi.Ref.String() != "" { | ||||
| 		key := slashpath.Join("/paths", jsonpointer.Escape(path)) | ||||
| 		s.references.addPathItemRef(key, pi) | ||||
| 	} | ||||
| 	s.analyzeOperation("GET", path, op.Get) | ||||
| 	s.analyzeOperation("PUT", path, op.Put) | ||||
| 	s.analyzeOperation("POST", path, op.Post) | ||||
| 	s.analyzeOperation("PATCH", path, op.Patch) | ||||
| 	s.analyzeOperation("DELETE", path, op.Delete) | ||||
| 	s.analyzeOperation("HEAD", path, op.Head) | ||||
| 	s.analyzeOperation("OPTIONS", path, op.Options) | ||||
| 	for i, param := range op.Parameters { | ||||
| 		refPref := slashpath.Join("/paths", jsonpointer.Escape(path), "parameters", strconv.Itoa(i)) | ||||
| 		if param.Ref.String() != "" { | ||||
| 			s.references.addParamRef(refPref, ¶m) | ||||
| 		} | ||||
| 		if param.Pattern != "" { | ||||
| 			s.patterns.addParameterPattern(refPref, param.Pattern) | ||||
| 		} | ||||
| 		if len(param.Enum) > 0 { | ||||
| 			s.enums.addParameterEnum(refPref, param.Enum) | ||||
| 		} | ||||
| 		if param.Items != nil { | ||||
| 			s.analyzeItems("items", param.Items, refPref, "parameter") | ||||
| 		} | ||||
| 		if param.Schema != nil { | ||||
| 			s.analyzeSchema("schema", *param.Schema, refPref) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *Spec) analyzeItems(name string, items *spec.Items, prefix, location string) { | ||||
| 	if items == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	refPref := slashpath.Join(prefix, name) | ||||
| 	s.analyzeItems(name, items.Items, refPref, location) | ||||
| 	if items.Ref.String() != "" { | ||||
| 		s.references.addItemsRef(refPref, items, location) | ||||
| 	} | ||||
| 	if items.Pattern != "" { | ||||
| 		s.patterns.addItemsPattern(refPref, items.Pattern) | ||||
| 	} | ||||
| 	if len(items.Enum) > 0 { | ||||
| 		s.enums.addItemsEnum(refPref, items.Enum) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *Spec) analyzeOperation(method, path string, op *spec.Operation) { | ||||
| 	if op == nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	for _, c := range op.Consumes { | ||||
| 		s.consumes[c] = struct{}{} | ||||
| 	} | ||||
| 	for _, c := range op.Produces { | ||||
| 		s.produces[c] = struct{}{} | ||||
| 	} | ||||
| 	for _, ss := range op.Security { | ||||
| 		for k := range ss { | ||||
| 			s.authSchemes[k] = struct{}{} | ||||
| 		} | ||||
| 	} | ||||
| 	if _, ok := s.operations[method]; !ok { | ||||
| 		s.operations[method] = make(map[string]*spec.Operation) | ||||
| 	} | ||||
| 	s.operations[method][path] = op | ||||
| 	prefix := slashpath.Join("/paths", jsonpointer.Escape(path), strings.ToLower(method)) | ||||
| 	for i, param := range op.Parameters { | ||||
| 		refPref := slashpath.Join(prefix, "parameters", strconv.Itoa(i)) | ||||
| 		if param.Ref.String() != "" { | ||||
| 			s.references.addParamRef(refPref, ¶m) | ||||
| 		} | ||||
| 		if param.Pattern != "" { | ||||
| 			s.patterns.addParameterPattern(refPref, param.Pattern) | ||||
| 		} | ||||
| 		if len(param.Enum) > 0 { | ||||
| 			s.enums.addParameterEnum(refPref, param.Enum) | ||||
| 		} | ||||
| 		s.analyzeItems("items", param.Items, refPref, "parameter") | ||||
| 		if param.In == "body" && param.Schema != nil { | ||||
| 			s.analyzeSchema("schema", *param.Schema, refPref) | ||||
| 		} | ||||
| 	} | ||||
| 	if op.Responses != nil { | ||||
| 		if op.Responses.Default != nil { | ||||
| 			refPref := slashpath.Join(prefix, "responses", "default") | ||||
| 			if op.Responses.Default.Ref.String() != "" { | ||||
| 				s.references.addResponseRef(refPref, op.Responses.Default) | ||||
| 			} | ||||
| 			for k, v := range op.Responses.Default.Headers { | ||||
| 				hRefPref := slashpath.Join(refPref, "headers", k) | ||||
| 				s.analyzeItems("items", v.Items, hRefPref, "header") | ||||
| 				if v.Pattern != "" { | ||||
| 					s.patterns.addHeaderPattern(hRefPref, v.Pattern) | ||||
| 				} | ||||
| 			} | ||||
| 			if op.Responses.Default.Schema != nil { | ||||
| 				s.analyzeSchema("schema", *op.Responses.Default.Schema, refPref) | ||||
| 			} | ||||
| 		} | ||||
| 		for k, res := range op.Responses.StatusCodeResponses { | ||||
| 			refPref := slashpath.Join(prefix, "responses", strconv.Itoa(k)) | ||||
| 			if res.Ref.String() != "" { | ||||
| 				s.references.addResponseRef(refPref, &res) | ||||
| 			} | ||||
| 			for k, v := range res.Headers { | ||||
| 				hRefPref := slashpath.Join(refPref, "headers", k) | ||||
| 				s.analyzeItems("items", v.Items, hRefPref, "header") | ||||
| 				if v.Pattern != "" { | ||||
| 					s.patterns.addHeaderPattern(hRefPref, v.Pattern) | ||||
| 				} | ||||
| 				if len(v.Enum) > 0 { | ||||
| 					s.enums.addHeaderEnum(hRefPref, v.Enum) | ||||
| 				} | ||||
| 			} | ||||
| 			if res.Schema != nil { | ||||
| 				s.analyzeSchema("schema", *res.Schema, refPref) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *Spec) analyzeSchema(name string, schema spec.Schema, prefix string) { | ||||
| 	refURI := slashpath.Join(prefix, jsonpointer.Escape(name)) | ||||
| 	schRef := SchemaRef{ | ||||
| 		Name:     name, | ||||
| 		Schema:   &schema, | ||||
| 		Ref:      spec.MustCreateRef("#" + refURI), | ||||
| 		TopLevel: prefix == "/definitions", | ||||
| 	} | ||||
|  | ||||
| 	s.allSchemas["#"+refURI] = schRef | ||||
|  | ||||
| 	if schema.Ref.String() != "" { | ||||
| 		s.references.addSchemaRef(refURI, schRef) | ||||
| 	} | ||||
| 	if schema.Pattern != "" { | ||||
| 		s.patterns.addSchemaPattern(refURI, schema.Pattern) | ||||
| 	} | ||||
| 	if len(schema.Enum) > 0 { | ||||
| 		s.enums.addSchemaEnum(refURI, schema.Enum) | ||||
| 	} | ||||
|  | ||||
| 	for k, v := range schema.Definitions { | ||||
| 		s.analyzeSchema(k, v, slashpath.Join(refURI, "definitions")) | ||||
| 	} | ||||
| 	for k, v := range schema.Properties { | ||||
| 		s.analyzeSchema(k, v, slashpath.Join(refURI, "properties")) | ||||
| 	} | ||||
| 	for k, v := range schema.PatternProperties { | ||||
| 		// NOTE: swagger 2.0 does not support PatternProperties. | ||||
| 		// However it is possible to analyze this in a schema | ||||
| 		s.analyzeSchema(k, v, slashpath.Join(refURI, "patternProperties")) | ||||
| 	} | ||||
| 	for i, v := range schema.AllOf { | ||||
| 		s.analyzeSchema(strconv.Itoa(i), v, slashpath.Join(refURI, "allOf")) | ||||
| 	} | ||||
| 	if len(schema.AllOf) > 0 { | ||||
| 		s.allOfs["#"+refURI] = schRef | ||||
| 	} | ||||
| 	for i, v := range schema.AnyOf { | ||||
| 		// NOTE: swagger 2.0 does not support anyOf constructs. | ||||
| 		// However it is possible to analyze this in a schema | ||||
| 		s.analyzeSchema(strconv.Itoa(i), v, slashpath.Join(refURI, "anyOf")) | ||||
| 	} | ||||
| 	for i, v := range schema.OneOf { | ||||
| 		// NOTE: swagger 2.0 does not support oneOf constructs. | ||||
| 		// However it is possible to analyze this in a schema | ||||
| 		s.analyzeSchema(strconv.Itoa(i), v, slashpath.Join(refURI, "oneOf")) | ||||
| 	} | ||||
| 	if schema.Not != nil { | ||||
| 		// NOTE: swagger 2.0 does not support "not" constructs. | ||||
| 		// However it is possible to analyze this in a schema | ||||
| 		s.analyzeSchema("not", *schema.Not, refURI) | ||||
| 	} | ||||
| 	if schema.AdditionalProperties != nil && schema.AdditionalProperties.Schema != nil { | ||||
| 		s.analyzeSchema("additionalProperties", *schema.AdditionalProperties.Schema, refURI) | ||||
| 	} | ||||
| 	if schema.AdditionalItems != nil && schema.AdditionalItems.Schema != nil { | ||||
| 		// NOTE: swagger 2.0 does not support AdditionalItems. | ||||
| 		// However it is possible to analyze this in a schema | ||||
| 		s.analyzeSchema("additionalItems", *schema.AdditionalItems.Schema, refURI) | ||||
| 	} | ||||
| 	if schema.Items != nil { | ||||
| 		if schema.Items.Schema != nil { | ||||
| 			s.analyzeSchema("items", *schema.Items.Schema, refURI) | ||||
| 		} | ||||
| 		for i, sch := range schema.Items.Schemas { | ||||
| 			s.analyzeSchema(strconv.Itoa(i), sch, slashpath.Join(refURI, "items")) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // SecurityRequirement is a representation of a security requirement for an operation | ||||
| type SecurityRequirement struct { | ||||
| 	Name   string | ||||
| 	Scopes []string | ||||
| } | ||||
|  | ||||
| // SecurityRequirementsFor gets the security requirements for the operation | ||||
| func (s *Spec) SecurityRequirementsFor(operation *spec.Operation) [][]SecurityRequirement { | ||||
| 	if s.spec.Security == nil && operation.Security == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	schemes := s.spec.Security | ||||
| 	if operation.Security != nil { | ||||
| 		schemes = operation.Security | ||||
| 	} | ||||
|  | ||||
| 	result := [][]SecurityRequirement{} | ||||
| 	for _, scheme := range schemes { | ||||
| 		if len(scheme) == 0 { | ||||
| 			// append a zero object for anonymous | ||||
| 			result = append(result, []SecurityRequirement{{}}) | ||||
| 			continue | ||||
| 		} | ||||
| 		var reqs []SecurityRequirement | ||||
| 		for k, v := range scheme { | ||||
| 			if v == nil { | ||||
| 				v = []string{} | ||||
| 			} | ||||
| 			reqs = append(reqs, SecurityRequirement{Name: k, Scopes: v}) | ||||
| 		} | ||||
| 		result = append(result, reqs) | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // SecurityDefinitionsForRequirements gets the matching security definitions for a set of requirements | ||||
| func (s *Spec) SecurityDefinitionsForRequirements(requirements []SecurityRequirement) map[string]spec.SecurityScheme { | ||||
| 	result := make(map[string]spec.SecurityScheme) | ||||
|  | ||||
| 	for _, v := range requirements { | ||||
| 		if definition, ok := s.spec.SecurityDefinitions[v.Name]; ok { | ||||
| 			if definition != nil { | ||||
| 				result[v.Name] = *definition | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // SecurityDefinitionsFor gets the matching security definitions for a set of requirements | ||||
| func (s *Spec) SecurityDefinitionsFor(operation *spec.Operation) map[string]spec.SecurityScheme { | ||||
| 	requirements := s.SecurityRequirementsFor(operation) | ||||
| 	if len(requirements) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	result := make(map[string]spec.SecurityScheme) | ||||
| 	for _, reqs := range requirements { | ||||
| 		for _, v := range reqs { | ||||
| 			if v.Name == "" { | ||||
| 				// optional requirement | ||||
| 				continue | ||||
| 			} | ||||
| 			if _, ok := result[v.Name]; ok { | ||||
| 				// duplicate requirement | ||||
| 				continue | ||||
| 			} | ||||
| 			if definition, ok := s.spec.SecurityDefinitions[v.Name]; ok { | ||||
| 				if definition != nil { | ||||
| 					result[v.Name] = *definition | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // ConsumesFor gets the mediatypes for the operation | ||||
| func (s *Spec) ConsumesFor(operation *spec.Operation) []string { | ||||
|  | ||||
| 	if len(operation.Consumes) == 0 { | ||||
| 		cons := make(map[string]struct{}, len(s.spec.Consumes)) | ||||
| 		for _, k := range s.spec.Consumes { | ||||
| 			cons[k] = struct{}{} | ||||
| 		} | ||||
| 		return s.structMapKeys(cons) | ||||
| 	} | ||||
|  | ||||
| 	cons := make(map[string]struct{}, len(operation.Consumes)) | ||||
| 	for _, c := range operation.Consumes { | ||||
| 		cons[c] = struct{}{} | ||||
| 	} | ||||
| 	return s.structMapKeys(cons) | ||||
| } | ||||
|  | ||||
| // ProducesFor gets the mediatypes for the operation | ||||
| func (s *Spec) ProducesFor(operation *spec.Operation) []string { | ||||
| 	if len(operation.Produces) == 0 { | ||||
| 		prod := make(map[string]struct{}, len(s.spec.Produces)) | ||||
| 		for _, k := range s.spec.Produces { | ||||
| 			prod[k] = struct{}{} | ||||
| 		} | ||||
| 		return s.structMapKeys(prod) | ||||
| 	} | ||||
|  | ||||
| 	prod := make(map[string]struct{}, len(operation.Produces)) | ||||
| 	for _, c := range operation.Produces { | ||||
| 		prod[c] = struct{}{} | ||||
| 	} | ||||
| 	return s.structMapKeys(prod) | ||||
| } | ||||
|  | ||||
| func mapKeyFromParam(param *spec.Parameter) string { | ||||
| 	return fmt.Sprintf("%s#%s", param.In, fieldNameFromParam(param)) | ||||
| } | ||||
|  | ||||
| func fieldNameFromParam(param *spec.Parameter) string { | ||||
| 	// TODO: this should be x-go-name | ||||
| 	if nm, ok := param.Extensions.GetString("go-name"); ok { | ||||
| 		return nm | ||||
| 	} | ||||
| 	return swag.ToGoName(param.Name) | ||||
| } | ||||
|  | ||||
| // ErrorOnParamFunc is a callback function to be invoked | ||||
| // whenever an error is encountered while resolving references | ||||
| // on parameters. | ||||
| // | ||||
| // This function takes as input the spec.Parameter which triggered the | ||||
| // error and the error itself. | ||||
| // | ||||
| // If the callback function returns false, the calling function should bail. | ||||
| // | ||||
| // If it returns true, the calling function should continue evaluating parameters. | ||||
| // A nil ErrorOnParamFunc must be evaluated as equivalent to panic(). | ||||
| type ErrorOnParamFunc func(spec.Parameter, error) bool | ||||
|  | ||||
| func (s *Spec) paramsAsMap(parameters []spec.Parameter, res map[string]spec.Parameter, callmeOnError ErrorOnParamFunc) { | ||||
| 	for _, param := range parameters { | ||||
| 		pr := param | ||||
| 		if pr.Ref.String() != "" { | ||||
| 			obj, _, err := pr.Ref.GetPointer().Get(s.spec) | ||||
| 			if err != nil { | ||||
| 				if callmeOnError != nil { | ||||
| 					if callmeOnError(param, fmt.Errorf("invalid reference: %q", pr.Ref.String())) { | ||||
| 						continue | ||||
| 					} | ||||
| 					break | ||||
| 				} else { | ||||
| 					panic(fmt.Sprintf("invalid reference: %q", pr.Ref.String())) | ||||
| 				} | ||||
| 			} | ||||
| 			if objAsParam, ok := obj.(spec.Parameter); ok { | ||||
| 				pr = objAsParam | ||||
| 			} else { | ||||
| 				if callmeOnError != nil { | ||||
| 					if callmeOnError(param, fmt.Errorf("resolved reference is not a parameter: %q", pr.Ref.String())) { | ||||
| 						continue | ||||
| 					} | ||||
| 					break | ||||
| 				} else { | ||||
| 					panic(fmt.Sprintf("resolved reference is not a parameter: %q", pr.Ref.String())) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		res[mapKeyFromParam(&pr)] = pr | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // ParametersFor the specified operation id. | ||||
| // | ||||
| // Assumes parameters properly resolve references if any and that | ||||
| // such references actually resolve to a parameter object. | ||||
| // Otherwise, panics. | ||||
| func (s *Spec) ParametersFor(operationID string) []spec.Parameter { | ||||
| 	return s.SafeParametersFor(operationID, nil) | ||||
| } | ||||
|  | ||||
| // SafeParametersFor the specified operation id. | ||||
| // | ||||
| // Does not assume parameters properly resolve references or that | ||||
| // such references actually resolve to a parameter object. | ||||
| // | ||||
| // Upon error, invoke a ErrorOnParamFunc callback with the erroneous | ||||
| // parameters. If the callback is set to nil, panics upon errors. | ||||
| func (s *Spec) SafeParametersFor(operationID string, callmeOnError ErrorOnParamFunc) []spec.Parameter { | ||||
| 	gatherParams := func(pi *spec.PathItem, op *spec.Operation) []spec.Parameter { | ||||
| 		bag := make(map[string]spec.Parameter) | ||||
| 		s.paramsAsMap(pi.Parameters, bag, callmeOnError) | ||||
| 		s.paramsAsMap(op.Parameters, bag, callmeOnError) | ||||
|  | ||||
| 		var res []spec.Parameter | ||||
| 		for _, v := range bag { | ||||
| 			res = append(res, v) | ||||
| 		} | ||||
| 		return res | ||||
| 	} | ||||
| 	for _, pi := range s.spec.Paths.Paths { | ||||
| 		if pi.Get != nil && pi.Get.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Get) | ||||
| 		} | ||||
| 		if pi.Head != nil && pi.Head.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Head) | ||||
| 		} | ||||
| 		if pi.Options != nil && pi.Options.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Options) | ||||
| 		} | ||||
| 		if pi.Post != nil && pi.Post.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Post) | ||||
| 		} | ||||
| 		if pi.Patch != nil && pi.Patch.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Patch) | ||||
| 		} | ||||
| 		if pi.Put != nil && pi.Put.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Put) | ||||
| 		} | ||||
| 		if pi.Delete != nil && pi.Delete.ID == operationID { | ||||
| 			return gatherParams(&pi, pi.Delete) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // ParamsFor the specified method and path. Aggregates them with the defaults etc, so it's all the params that | ||||
| // apply for the method and path. | ||||
| // | ||||
| // Assumes parameters properly resolve references if any and that | ||||
| // such references actually resolve to a parameter object. | ||||
| // Otherwise, panics. | ||||
| func (s *Spec) ParamsFor(method, path string) map[string]spec.Parameter { | ||||
| 	return s.SafeParamsFor(method, path, nil) | ||||
| } | ||||
|  | ||||
| // SafeParamsFor the specified method and path. Aggregates them with the defaults etc, so it's all the params that | ||||
| // apply for the method and path. | ||||
| // | ||||
| // Does not assume parameters properly resolve references or that | ||||
| // such references actually resolve to a parameter object. | ||||
| // | ||||
| // Upon error, invoke a ErrorOnParamFunc callback with the erroneous | ||||
| // parameters. If the callback is set to nil, panics upon errors. | ||||
| func (s *Spec) SafeParamsFor(method, path string, callmeOnError ErrorOnParamFunc) map[string]spec.Parameter { | ||||
| 	res := make(map[string]spec.Parameter) | ||||
| 	if pi, ok := s.spec.Paths.Paths[path]; ok { | ||||
| 		s.paramsAsMap(pi.Parameters, res, callmeOnError) | ||||
| 		s.paramsAsMap(s.operations[strings.ToUpper(method)][path].Parameters, res, callmeOnError) | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
|  | ||||
| // OperationForName gets the operation for the given id | ||||
| func (s *Spec) OperationForName(operationID string) (string, string, *spec.Operation, bool) { | ||||
| 	for method, pathItem := range s.operations { | ||||
| 		for path, op := range pathItem { | ||||
| 			if operationID == op.ID { | ||||
| 				return method, path, op, true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return "", "", nil, false | ||||
| } | ||||
|  | ||||
| // OperationFor the given method and path | ||||
| func (s *Spec) OperationFor(method, path string) (*spec.Operation, bool) { | ||||
| 	if mp, ok := s.operations[strings.ToUpper(method)]; ok { | ||||
| 		op, fn := mp[path] | ||||
| 		return op, fn | ||||
| 	} | ||||
| 	return nil, false | ||||
| } | ||||
|  | ||||
| // Operations gathers all the operations specified in the spec document | ||||
| func (s *Spec) Operations() map[string]map[string]*spec.Operation { | ||||
| 	return s.operations | ||||
| } | ||||
|  | ||||
| func (s *Spec) structMapKeys(mp map[string]struct{}) []string { | ||||
| 	if len(mp) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	result := make([]string, 0, len(mp)) | ||||
| 	for k := range mp { | ||||
| 		result = append(result, k) | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // AllPaths returns all the paths in the swagger spec | ||||
| func (s *Spec) AllPaths() map[string]spec.PathItem { | ||||
| 	if s.spec == nil || s.spec.Paths == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return s.spec.Paths.Paths | ||||
| } | ||||
|  | ||||
| // OperationIDs gets all the operation ids based on method an dpath | ||||
| func (s *Spec) OperationIDs() []string { | ||||
| 	if len(s.operations) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	result := make([]string, 0, len(s.operations)) | ||||
| 	for method, v := range s.operations { | ||||
| 		for p, o := range v { | ||||
| 			if o.ID != "" { | ||||
| 				result = append(result, o.ID) | ||||
| 			} else { | ||||
| 				result = append(result, fmt.Sprintf("%s %s", strings.ToUpper(method), p)) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // OperationMethodPaths gets all the operation ids based on method an dpath | ||||
| func (s *Spec) OperationMethodPaths() []string { | ||||
| 	if len(s.operations) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	result := make([]string, 0, len(s.operations)) | ||||
| 	for method, v := range s.operations { | ||||
| 		for p := range v { | ||||
| 			result = append(result, fmt.Sprintf("%s %s", strings.ToUpper(method), p)) | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| // RequiredConsumes gets all the distinct consumes that are specified in the specification document | ||||
| func (s *Spec) RequiredConsumes() []string { | ||||
| 	return s.structMapKeys(s.consumes) | ||||
| } | ||||
|  | ||||
| // RequiredProduces gets all the distinct produces that are specified in the specification document | ||||
| func (s *Spec) RequiredProduces() []string { | ||||
| 	return s.structMapKeys(s.produces) | ||||
| } | ||||
|  | ||||
| // RequiredSecuritySchemes gets all the distinct security schemes that are specified in the swagger spec | ||||
| func (s *Spec) RequiredSecuritySchemes() []string { | ||||
| 	return s.structMapKeys(s.authSchemes) | ||||
| } | ||||
|  | ||||
| // SchemaRef is a reference to a schema | ||||
| type SchemaRef struct { | ||||
| 	Name     string | ||||
| 	Ref      spec.Ref | ||||
| 	Schema   *spec.Schema | ||||
| 	TopLevel bool | ||||
| } | ||||
|  | ||||
| // SchemasWithAllOf returns schema references to all schemas that are defined | ||||
| // with an allOf key | ||||
| func (s *Spec) SchemasWithAllOf() (result []SchemaRef) { | ||||
| 	for _, v := range s.allOfs { | ||||
| 		result = append(result, v) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllDefinitions returns schema references for all the definitions that were discovered | ||||
| func (s *Spec) AllDefinitions() (result []SchemaRef) { | ||||
| 	for _, v := range s.allSchemas { | ||||
| 		result = append(result, v) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllDefinitionReferences returns json refs for all the discovered schemas | ||||
| func (s *Spec) AllDefinitionReferences() (result []string) { | ||||
| 	for _, v := range s.references.schemas { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllParameterReferences returns json refs for all the discovered parameters | ||||
| func (s *Spec) AllParameterReferences() (result []string) { | ||||
| 	for _, v := range s.references.parameters { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllResponseReferences returns json refs for all the discovered responses | ||||
| func (s *Spec) AllResponseReferences() (result []string) { | ||||
| 	for _, v := range s.references.responses { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllPathItemReferences returns the references for all the items | ||||
| func (s *Spec) AllPathItemReferences() (result []string) { | ||||
| 	for _, v := range s.references.pathItems { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllItemsReferences returns the references for all the items in simple schemas (parameters or headers). | ||||
| // | ||||
| // NOTE: since Swagger 2.0 forbids $ref in simple params, this should always yield an empty slice for a valid | ||||
| // Swagger 2.0 spec. | ||||
| func (s *Spec) AllItemsReferences() (result []string) { | ||||
| 	for _, v := range s.references.items { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllReferences returns all the references found in the document, with possible duplicates | ||||
| func (s *Spec) AllReferences() (result []string) { | ||||
| 	for _, v := range s.references.allRefs { | ||||
| 		result = append(result, v.String()) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| // AllRefs returns all the unique references found in the document | ||||
| func (s *Spec) AllRefs() (result []spec.Ref) { | ||||
| 	set := make(map[string]struct{}) | ||||
| 	for _, v := range s.references.allRefs { | ||||
| 		a := v.String() | ||||
| 		if a == "" { | ||||
| 			continue | ||||
| 		} | ||||
| 		if _, ok := set[a]; !ok { | ||||
| 			set[a] = struct{}{} | ||||
| 			result = append(result, v) | ||||
| 		} | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func cloneStringMap(source map[string]string) map[string]string { | ||||
| 	res := make(map[string]string, len(source)) | ||||
| 	for k, v := range source { | ||||
| 		res[k] = v | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
|  | ||||
| func cloneEnumMap(source map[string][]interface{}) map[string][]interface{} { | ||||
| 	res := make(map[string][]interface{}, len(source)) | ||||
| 	for k, v := range source { | ||||
| 		res[k] = v | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
|  | ||||
| // ParameterPatterns returns all the patterns found in parameters | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) ParameterPatterns() map[string]string { | ||||
| 	return cloneStringMap(s.patterns.parameters) | ||||
| } | ||||
|  | ||||
| // HeaderPatterns returns all the patterns found in response headers | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) HeaderPatterns() map[string]string { | ||||
| 	return cloneStringMap(s.patterns.headers) | ||||
| } | ||||
|  | ||||
| // ItemsPatterns returns all the patterns found in simple array items | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) ItemsPatterns() map[string]string { | ||||
| 	return cloneStringMap(s.patterns.items) | ||||
| } | ||||
|  | ||||
| // SchemaPatterns returns all the patterns found in schemas | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) SchemaPatterns() map[string]string { | ||||
| 	return cloneStringMap(s.patterns.schemas) | ||||
| } | ||||
|  | ||||
| // AllPatterns returns all the patterns found in the spec | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) AllPatterns() map[string]string { | ||||
| 	return cloneStringMap(s.patterns.allPatterns) | ||||
| } | ||||
|  | ||||
| // ParameterEnums returns all the enums found in parameters | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) ParameterEnums() map[string][]interface{} { | ||||
| 	return cloneEnumMap(s.enums.parameters) | ||||
| } | ||||
|  | ||||
| // HeaderEnums returns all the enums found in response headers | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) HeaderEnums() map[string][]interface{} { | ||||
| 	return cloneEnumMap(s.enums.headers) | ||||
| } | ||||
|  | ||||
| // ItemsEnums returns all the enums found in simple array items | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) ItemsEnums() map[string][]interface{} { | ||||
| 	return cloneEnumMap(s.enums.items) | ||||
| } | ||||
|  | ||||
| // SchemaEnums returns all the enums found in schemas | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) SchemaEnums() map[string][]interface{} { | ||||
| 	return cloneEnumMap(s.enums.schemas) | ||||
| } | ||||
|  | ||||
| // AllEnums returns all the enums found in the spec | ||||
| // the map is cloned to avoid accidental changes | ||||
| func (s *Spec) AllEnums() map[string][]interface{} { | ||||
| 	return cloneEnumMap(s.enums.allEnums) | ||||
| } | ||||
							
								
								
									
										33
									
								
								vendor/github.com/go-openapi/analysis/appveyor.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								vendor/github.com/go-openapi/analysis/appveyor.yml
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| version: "0.1.{build}" | ||||
|  | ||||
| clone_folder: C:\go-openapi\analysis | ||||
| shallow_clone: true # for startup speed | ||||
| pull_requests: | ||||
|   do_not_increment_build_number: true | ||||
|  | ||||
| #skip_tags: true | ||||
| #skip_branch_with_pr: true | ||||
|  | ||||
| # appveyor.yml | ||||
| build: off | ||||
|  | ||||
| environment: | ||||
|   GOPATH: c:\gopath | ||||
|  | ||||
| stack: go 1.12 | ||||
|  | ||||
| test_script: | ||||
|   - go test -v -timeout 20m ./... | ||||
| #artifacts: | ||||
| #  - path: '%GOPATH%\bin\*.exe' | ||||
| deploy: off | ||||
|  | ||||
| notifications: | ||||
|   - provider: Slack | ||||
|     incoming_webhook: https://hooks.slack.com/services/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 | ||||
|     auth_token: | ||||
|       secure: Sf7kZf7ZGbnwWUMpffHwMu5A0cHkLK2MYY32LNTPj4+/3qC3Ghl7+9v4TSLOqOlCwdRNjOGblAq7s+GDJed6/xgRQl1JtCi1klzZNrYX4q01pgTPvvGcwbBkIYgeMaPeIRcK9OZnud7sRXdttozgTOpytps2U6Js32ip7uj5mHSg2ub0FwoSJwlS6dbezZ8+eDhoha0F/guY99BEwx8Bd+zROrT2TFGsSGOFGN6wFc7moCqTHO/YkWib13a2QNXqOxCCVBy/lt76Wp+JkeFppjHlzs/2lP3EAk13RIUAaesdEUHvIHrzCyNJEd3/+KO2DzsWOYfpktd+KBCvgaYOsoo7ubdT3IROeAegZdCgo/6xgCEsmFc9ZcqCfN5yNx2A+BZ2Vwmpws+bQ1E1+B5HDzzaiLcYfG4X2O210QVGVDLWsv1jqD+uPYeHY2WRfh5ZsIUFvaqgUEnwHwrK44/8REAhQavt1QAj5uJpsRd7CkRVPWRNK+yIky+wgbVUFEchRNmS55E7QWf+W4+4QZkQi7vUTMc9nbTUu2Es9NfvfudOpM2wZbn98fjpb/qq/nRv6Bk+ca+7XD5/IgNLMbWp2ouDdzbiHLCOfDUiHiDJhLfFZx9Bwo7ZwfzeOlbrQX66bx7xRKYmOe4DLrXhNcpbsMa8qbfxlZRCmYbubB/Y8h4= | ||||
|     channel: bots | ||||
|     on_build_success: false | ||||
|     on_build_failure: true | ||||
|     on_build_status_changed: true | ||||
							
								
								
									
										47
									
								
								vendor/github.com/go-openapi/analysis/debug.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								vendor/github.com/go-openapi/analysis/debug.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package analysis | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	// Debug is true when the SWAGGER_DEBUG env var is not empty. | ||||
| 	// It enables a more verbose logging of the spec analyzer. | ||||
| 	Debug = os.Getenv("SWAGGER_DEBUG") != "" | ||||
| 	// analysisLogger is a debug logger for this package | ||||
| 	analysisLogger *log.Logger | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	debugOptions() | ||||
| } | ||||
|  | ||||
| func debugOptions() { | ||||
| 	analysisLogger = log.New(os.Stdout, "analysis:", log.LstdFlags) | ||||
| } | ||||
|  | ||||
| func debugLog(msg string, args ...interface{}) { | ||||
| 	// A private, trivial trace logger, based on go-openapi/spec/expander.go:debugLog() | ||||
| 	if Debug { | ||||
| 		_, file1, pos1, _ := runtime.Caller(1) | ||||
| 		analysisLogger.Printf("%s:%d: %s", filepath.Base(file1), pos1, fmt.Sprintf(msg, args...)) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										43
									
								
								vendor/github.com/go-openapi/analysis/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								vendor/github.com/go-openapi/analysis/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| /* | ||||
| Package analysis provides methods to work with a Swagger specification document from | ||||
| package go-openapi/spec. | ||||
|  | ||||
| Analyzing a specification | ||||
|  | ||||
| An analysed specification object (type Spec) provides methods to work with swagger definition. | ||||
|  | ||||
| Flattening or expanding a specification | ||||
|  | ||||
| Flattening a specification bundles all remote $ref in the main spec document. | ||||
| Depending on flattening options, additional preprocessing may take place: | ||||
|   - full flattening: replacing all inline complex constructs by a named entry in #/definitions | ||||
|   - expand: replace all $ref's in the document by their expanded content | ||||
|  | ||||
| Merging several specifications | ||||
|  | ||||
| Mixin several specifications merges all Swagger constructs, and warns about found conflicts. | ||||
|  | ||||
| Fixing a specification | ||||
|  | ||||
| Unmarshalling a specification with golang json unmarshalling may lead to | ||||
| some unwanted result on present but empty fields. | ||||
|  | ||||
| Analyzing a Swagger schema | ||||
|  | ||||
| Swagger schemas are analyzed to determine their complexity and qualify their content. | ||||
| */ | ||||
| package analysis | ||||
							
								
								
									
										76
									
								
								vendor/github.com/go-openapi/analysis/fixer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								vendor/github.com/go-openapi/analysis/fixer.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package analysis | ||||
|  | ||||
| import "github.com/go-openapi/spec" | ||||
|  | ||||
| // FixEmptyResponseDescriptions replaces empty ("") response | ||||
| // descriptions in the input with "(empty)" to ensure that the | ||||
| // resulting Swagger is stays valid.  The problem appears to arise | ||||
| // from reading in valid specs that have a explicit response | ||||
| // description of "" (valid, response.description is required), but | ||||
| // due to zero values being omitted upon re-serializing (omitempty) we | ||||
| // lose them unless we stick some chars in there. | ||||
| func FixEmptyResponseDescriptions(s *spec.Swagger) { | ||||
| 	if s.Paths != nil { | ||||
| 		for _, v := range s.Paths.Paths { | ||||
| 			if v.Get != nil { | ||||
| 				FixEmptyDescs(v.Get.Responses) | ||||
| 			} | ||||
| 			if v.Put != nil { | ||||
| 				FixEmptyDescs(v.Put.Responses) | ||||
| 			} | ||||
| 			if v.Post != nil { | ||||
| 				FixEmptyDescs(v.Post.Responses) | ||||
| 			} | ||||
| 			if v.Delete != nil { | ||||
| 				FixEmptyDescs(v.Delete.Responses) | ||||
| 			} | ||||
| 			if v.Options != nil { | ||||
| 				FixEmptyDescs(v.Options.Responses) | ||||
| 			} | ||||
| 			if v.Head != nil { | ||||
| 				FixEmptyDescs(v.Head.Responses) | ||||
| 			} | ||||
| 			if v.Patch != nil { | ||||
| 				FixEmptyDescs(v.Patch.Responses) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	for k, v := range s.Responses { | ||||
| 		FixEmptyDesc(&v) | ||||
| 		s.Responses[k] = v | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // FixEmptyDescs adds "(empty)" as the description for any Response in | ||||
| // the given Responses object that doesn't already have one. | ||||
| func FixEmptyDescs(rs *spec.Responses) { | ||||
| 	FixEmptyDesc(rs.Default) | ||||
| 	for k, v := range rs.StatusCodeResponses { | ||||
| 		FixEmptyDesc(&v) | ||||
| 		rs.StatusCodeResponses[k] = v | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // FixEmptyDesc adds "(empty)" as the description to the given | ||||
| // Response object if it doesn't already have one and isn't a | ||||
| // ref. No-op on nil input. | ||||
| func FixEmptyDesc(rs *spec.Response) { | ||||
| 	if rs == nil || rs.Description != "" || rs.Ref.Ref.GetURL() != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	rs.Description = "(empty)" | ||||
| } | ||||
							
								
								
									
										1729
									
								
								vendor/github.com/go-openapi/analysis/flatten.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1729
									
								
								vendor/github.com/go-openapi/analysis/flatten.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										13
									
								
								vendor/github.com/go-openapi/analysis/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								vendor/github.com/go-openapi/analysis/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| module github.com/go-openapi/analysis | ||||
|  | ||||
| require ( | ||||
| 	github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect | ||||
| 	github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect | ||||
| 	github.com/go-openapi/errors v0.19.2 // indirect | ||||
| 	github.com/go-openapi/jsonpointer v0.19.2 | ||||
| 	github.com/go-openapi/loads v0.19.0 | ||||
| 	github.com/go-openapi/spec v0.19.2 | ||||
| 	github.com/go-openapi/strfmt v0.19.0 | ||||
| 	github.com/go-openapi/swag v0.19.2 | ||||
| 	github.com/stretchr/testify v1.3.0 | ||||
| ) | ||||
							
								
								
									
										79
									
								
								vendor/github.com/go-openapi/analysis/go.sum
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								vendor/github.com/go-openapi/analysis/go.sum
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | ||||
| github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= | ||||
| github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= | ||||
| github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= | ||||
| github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= | ||||
| github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= | ||||
| github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA= | ||||
| github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= | ||||
| github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is= | ||||
| github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= | ||||
| github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= | ||||
| github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0= | ||||
| github.com/go-openapi/errors v0.19.2 h1:a2kIyV3w+OS3S97zxUndRVD46+FhGOUBDFY7nmu4CsY= | ||||
| github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94= | ||||
| github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= | ||||
| github.com/go-openapi/jsonpointer v0.19.2 h1:A9+F4Dc/MCNB5jibxf6rRvOvR/iFgQdyNx9eIhnGqq0= | ||||
| github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= | ||||
| github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= | ||||
| github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w= | ||||
| github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= | ||||
| github.com/go-openapi/loads v0.19.0 h1:wCOBNscACI8L93tt5tvB2zOMkJ098XCw3fP0BY2ybDA= | ||||
| github.com/go-openapi/loads v0.19.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= | ||||
| github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= | ||||
| github.com/go-openapi/spec v0.19.2 h1:SStNd1jRcYtfKCN7R0laGNs80WYYvn5CbBjM2sOmCrE= | ||||
| github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= | ||||
| github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU= | ||||
| github.com/go-openapi/strfmt v0.19.0 h1:0Dn9qy1G9+UJfRU7TR8bmdGxb4uifB7HNrJjOnV0yPk= | ||||
| github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY= | ||||
| github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= | ||||
| github.com/go-openapi/swag v0.19.2 h1:jvO6bCMBEilGwMfHhrd61zIID4oIFdwb76V17SM88dE= | ||||
| github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= | ||||
| github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= | ||||
| github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||||
| github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||||
| github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||||
| github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= | ||||
| github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||||
| github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||||
| github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= | ||||
| github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63 h1:nTT4s92Dgz2HlrB2NaMgvlfqHH39OgMhA7z3PK7PGD4= | ||||
| github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= | ||||
| github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= | ||||
| github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= | ||||
| github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= | ||||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||||
| github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||||
| golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= | ||||
| golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||||
| gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
| gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||||
| gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
							
								
								
									
										29
									
								
								vendor/github.com/go-openapi/analysis/internal/post_go18.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/go-openapi/analysis/internal/post_go18.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| // +build go1.8 | ||||
|  | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package internal | ||||
|  | ||||
| import "net/url" | ||||
|  | ||||
| // PathUnescape provides url.PathUnescape(), with seamless | ||||
| // go version support for pre-go1.8 | ||||
| // | ||||
| // TODO: this function is currently defined in go-openapi/swag, | ||||
| // but unexported. We might chose to export it, or simple phase | ||||
| // out pre-go1.8 support. | ||||
| func PathUnescape(path string) (string, error) { | ||||
| 	return url.PathUnescape(path) | ||||
| } | ||||
							
								
								
									
										29
									
								
								vendor/github.com/go-openapi/analysis/internal/pre_go18.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/go-openapi/analysis/internal/pre_go18.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| // +build !go1.8 | ||||
|  | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package internal | ||||
|  | ||||
| import "net/url" | ||||
|  | ||||
| // PathUnescape provides url.PathUnescape(), with seamless | ||||
| // go version support for pre-go1.8 | ||||
| // | ||||
| // TODO: this function is currently defined in go-openapi/swag, | ||||
| // but unexported. We might chose to export it, or simple phase | ||||
| // out pre-go1.8 support. | ||||
| func PathUnescape(path string) (string, error) { | ||||
| 	return url.QueryUnescape(path) | ||||
| } | ||||
							
								
								
									
										425
									
								
								vendor/github.com/go-openapi/analysis/mixin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										425
									
								
								vendor/github.com/go-openapi/analysis/mixin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,425 @@ | ||||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //    http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package analysis | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
|  | ||||
| 	"github.com/go-openapi/spec" | ||||
| ) | ||||
|  | ||||
| // Mixin modifies the primary swagger spec by adding the paths and | ||||
| // definitions from the mixin specs. Top level parameters and | ||||
| // responses from the mixins are also carried over. Operation id | ||||
| // collisions are avoided by appending "Mixin<N>" but only if | ||||
| // needed. | ||||
| // | ||||
| // The following parts of primary are subject to merge, filling empty details | ||||
| //   - Info | ||||
| //   - BasePath | ||||
| //   - Host | ||||
| //   - ExternalDocs | ||||
| // | ||||
| // Consider calling FixEmptyResponseDescriptions() on the modified primary | ||||
| // if you read them from storage and they are valid to start with. | ||||
| // | ||||
| // Entries in "paths", "definitions", "parameters" and "responses" are | ||||
| // added to the primary in the order of the given mixins. If the entry | ||||
| // already exists in primary it is skipped with a warning message. | ||||
| // | ||||
| // The count of skipped entries (from collisions) is returned so any | ||||
| // deviation from the number expected can flag a warning in your build | ||||
| // scripts. Carefully review the collisions before accepting them; | ||||
| // consider renaming things if possible. | ||||
| // | ||||
| // No key normalization takes place (paths, type defs, | ||||
| // etc). Ensure they are canonical if your downstream tools do | ||||
| // key normalization of any form. | ||||
| // | ||||
| // Merging schemes (http, https), and consumers/producers do not account for | ||||
| // collisions. | ||||
| func Mixin(primary *spec.Swagger, mixins ...*spec.Swagger) []string { | ||||
| 	skipped := make([]string, 0, len(mixins)) | ||||
| 	opIds := getOpIds(primary) | ||||
| 	initPrimary(primary) | ||||
|  | ||||
| 	for i, m := range mixins { | ||||
| 		skipped = append(skipped, mergeSwaggerProps(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeConsumes(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeProduces(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeTags(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeSchemes(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeSecurityDefinitions(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeSecurityRequirements(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeDefinitions(primary, m)...) | ||||
|  | ||||
| 		// merging paths requires a map of operationIDs to work with | ||||
| 		skipped = append(skipped, mergePaths(primary, m, opIds, i)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeParameters(primary, m)...) | ||||
|  | ||||
| 		skipped = append(skipped, mergeResponses(primary, m)...) | ||||
| 	} | ||||
| 	return skipped | ||||
| } | ||||
|  | ||||
| // getOpIds extracts all the paths.<path>.operationIds from the given | ||||
| // spec and returns them as the keys in a map with 'true' values. | ||||
| func getOpIds(s *spec.Swagger) map[string]bool { | ||||
| 	rv := make(map[string]bool) | ||||
| 	if s.Paths == nil { | ||||
| 		return rv | ||||
| 	} | ||||
| 	for _, v := range s.Paths.Paths { | ||||
| 		piops := pathItemOps(v) | ||||
| 		for _, op := range piops { | ||||
| 			rv[op.ID] = true | ||||
| 		} | ||||
| 	} | ||||
| 	return rv | ||||
| } | ||||
|  | ||||
| func pathItemOps(p spec.PathItem) []*spec.Operation { | ||||
| 	var rv []*spec.Operation | ||||
| 	rv = appendOp(rv, p.Get) | ||||
| 	rv = appendOp(rv, p.Put) | ||||
| 	rv = appendOp(rv, p.Post) | ||||
| 	rv = appendOp(rv, p.Delete) | ||||
| 	rv = appendOp(rv, p.Head) | ||||
| 	rv = appendOp(rv, p.Patch) | ||||
| 	return rv | ||||
| } | ||||
|  | ||||
| func appendOp(ops []*spec.Operation, op *spec.Operation) []*spec.Operation { | ||||
| 	if op == nil { | ||||
| 		return ops | ||||
| 	} | ||||
| 	return append(ops, op) | ||||
| } | ||||
|  | ||||
| func mergeSecurityDefinitions(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for k, v := range m.SecurityDefinitions { | ||||
| 		if _, exists := primary.SecurityDefinitions[k]; exists { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"SecurityDefinitions entry '%v' already exists in primary or higher priority mixin, skipping\n", k) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.SecurityDefinitions[k] = v | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergeSecurityRequirements(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for _, v := range m.Security { | ||||
| 		found := false | ||||
| 		for _, vv := range primary.Security { | ||||
| 			if reflect.DeepEqual(v, vv) { | ||||
| 				found = true | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 		if found { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"Security requirement: '%v' already exists in primary or higher priority mixin, skipping\n", v) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Security = append(primary.Security, v) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergeDefinitions(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for k, v := range m.Definitions { | ||||
| 		// assume name collisions represent IDENTICAL type. careful. | ||||
| 		if _, exists := primary.Definitions[k]; exists { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"definitions entry '%v' already exists in primary or higher priority mixin, skipping\n", k) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Definitions[k] = v | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergePaths(primary *spec.Swagger, m *spec.Swagger, opIds map[string]bool, mixIndex int) (skipped []string) { | ||||
| 	if m.Paths != nil { | ||||
| 		for k, v := range m.Paths.Paths { | ||||
| 			if _, exists := primary.Paths.Paths[k]; exists { | ||||
| 				warn := fmt.Sprintf( | ||||
| 					"paths entry '%v' already exists in primary or higher priority mixin, skipping\n", k) | ||||
| 				skipped = append(skipped, warn) | ||||
| 				continue | ||||
| 			} | ||||
|  | ||||
| 			// Swagger requires that operationIds be | ||||
| 			// unique within a spec. If we find a | ||||
| 			// collision we append "Mixin0" to the | ||||
| 			// operatoinId we are adding, where 0 is mixin | ||||
| 			// index.  We assume that operationIds with | ||||
| 			// all the proivded specs are already unique. | ||||
| 			piops := pathItemOps(v) | ||||
| 			for _, piop := range piops { | ||||
| 				if opIds[piop.ID] { | ||||
| 					piop.ID = fmt.Sprintf("%v%v%v", piop.ID, "Mixin", mixIndex) | ||||
| 				} | ||||
| 				opIds[piop.ID] = true | ||||
| 			} | ||||
| 			primary.Paths.Paths[k] = v | ||||
| 		} | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergeParameters(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for k, v := range m.Parameters { | ||||
| 		// could try to rename on conflict but would | ||||
| 		// have to fix $refs in the mixin. Complain | ||||
| 		// for now | ||||
| 		if _, exists := primary.Parameters[k]; exists { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"top level parameters entry '%v' already exists in primary or higher priority mixin, skipping\n", k) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Parameters[k] = v | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergeResponses(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for k, v := range m.Responses { | ||||
| 		// could try to rename on conflict but would | ||||
| 		// have to fix $refs in the mixin. Complain | ||||
| 		// for now | ||||
| 		if _, exists := primary.Responses[k]; exists { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"top level responses entry '%v' already exists in primary or higher priority mixin, skipping\n", k) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Responses[k] = v | ||||
| 	} | ||||
| 	return skipped | ||||
| } | ||||
|  | ||||
| func mergeConsumes(primary *spec.Swagger, m *spec.Swagger) []string { | ||||
| 	for _, v := range m.Consumes { | ||||
| 		found := false | ||||
| 		for _, vv := range primary.Consumes { | ||||
| 			if v == vv { | ||||
| 				found = true | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 		if found { | ||||
| 			// no warning here: we just skip it | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Consumes = append(primary.Consumes, v) | ||||
| 	} | ||||
| 	return []string{} | ||||
| } | ||||
|  | ||||
| func mergeProduces(primary *spec.Swagger, m *spec.Swagger) []string { | ||||
| 	for _, v := range m.Produces { | ||||
| 		found := false | ||||
| 		for _, vv := range primary.Produces { | ||||
| 			if v == vv { | ||||
| 				found = true | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 		if found { | ||||
| 			// no warning here: we just skip it | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Produces = append(primary.Produces, v) | ||||
| 	} | ||||
| 	return []string{} | ||||
| } | ||||
|  | ||||
| func mergeTags(primary *spec.Swagger, m *spec.Swagger) (skipped []string) { | ||||
| 	for _, v := range m.Tags { | ||||
| 		found := false | ||||
| 		for _, vv := range primary.Tags { | ||||
| 			if v.Name == vv.Name { | ||||
| 				found = true | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 		if found { | ||||
| 			warn := fmt.Sprintf( | ||||
| 				"top level tags entry with name '%v' already exists in primary or higher priority mixin, skipping\n", v.Name) | ||||
| 			skipped = append(skipped, warn) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Tags = append(primary.Tags, v) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func mergeSchemes(primary *spec.Swagger, m *spec.Swagger) []string { | ||||
| 	for _, v := range m.Schemes { | ||||
| 		found := false | ||||
| 		for _, vv := range primary.Schemes { | ||||
| 			if v == vv { | ||||
| 				found = true | ||||
| 				break | ||||
| 			} | ||||
| 		} | ||||
| 		if found { | ||||
| 			// no warning here: we just skip it | ||||
| 			continue | ||||
| 		} | ||||
| 		primary.Schemes = append(primary.Schemes, v) | ||||
| 	} | ||||
| 	return []string{} | ||||
| } | ||||
|  | ||||
| func mergeSwaggerProps(primary *spec.Swagger, m *spec.Swagger) []string { | ||||
| 	var skipped []string | ||||
| 	primary.Extensions, skipped = mergeExtensions(primary.Extensions, m.Extensions) | ||||
|  | ||||
| 	// merging details in swagger top properties | ||||
| 	if primary.Host == "" { | ||||
| 		primary.Host = m.Host | ||||
| 	} | ||||
| 	if primary.BasePath == "" { | ||||
| 		primary.BasePath = m.BasePath | ||||
| 	} | ||||
| 	if primary.Info == nil { | ||||
| 		primary.Info = m.Info | ||||
| 	} else if m.Info != nil { | ||||
| 		var sk []string | ||||
| 		primary.Info.Extensions, sk = mergeExtensions(primary.Info.Extensions, m.Info.Extensions) | ||||
| 		skipped = append(skipped, sk...) | ||||
| 		if primary.Info.Description == "" { | ||||
| 			primary.Info.Description = m.Info.Description | ||||
| 		} | ||||
| 		if primary.Info.Title == "" { | ||||
| 			primary.Info.Description = m.Info.Description | ||||
| 		} | ||||
| 		if primary.Info.TermsOfService == "" { | ||||
| 			primary.Info.TermsOfService = m.Info.TermsOfService | ||||
| 		} | ||||
| 		if primary.Info.Version == "" { | ||||
| 			primary.Info.Version = m.Info.Version | ||||
| 		} | ||||
|  | ||||
| 		if primary.Info.Contact == nil { | ||||
| 			primary.Info.Contact = m.Info.Contact | ||||
| 		} else if m.Info.Contact != nil { | ||||
| 			if primary.Info.Contact.Name == "" { | ||||
| 				primary.Info.Contact.Name = m.Info.Contact.Name | ||||
| 			} | ||||
| 			if primary.Info.Contact.URL == "" { | ||||
| 				primary.Info.Contact.URL = m.Info.Contact.URL | ||||
| 			} | ||||
| 			if primary.Info.Contact.Email == "" { | ||||
| 				primary.Info.Contact.Email = m.Info.Contact.Email | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if primary.Info.License == nil { | ||||
| 			primary.Info.License = m.Info.License | ||||
| 		} else if m.Info.License != nil { | ||||
| 			if primary.Info.License.Name == "" { | ||||
| 				primary.Info.License.Name = m.Info.License.Name | ||||
| 			} | ||||
| 			if primary.Info.License.URL == "" { | ||||
| 				primary.Info.License.URL = m.Info.License.URL | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
| 	if primary.ExternalDocs == nil { | ||||
| 		primary.ExternalDocs = m.ExternalDocs | ||||
| 	} else if m.ExternalDocs != nil { | ||||
| 		if primary.ExternalDocs.Description == "" { | ||||
| 			primary.ExternalDocs.Description = m.ExternalDocs.Description | ||||
| 		} | ||||
| 		if primary.ExternalDocs.URL == "" { | ||||
| 			primary.ExternalDocs.URL = m.ExternalDocs.URL | ||||
| 		} | ||||
| 	} | ||||
| 	return skipped | ||||
| } | ||||
|  | ||||
| func mergeExtensions(primary spec.Extensions, m spec.Extensions) (result spec.Extensions, skipped []string) { | ||||
| 	if primary == nil { | ||||
| 		result = m | ||||
| 		return | ||||
| 	} | ||||
| 	if m == nil { | ||||
| 		result = primary | ||||
| 		return | ||||
| 	} | ||||
| 	result = primary | ||||
| 	for k, v := range m { | ||||
| 		if _, found := primary[k]; found { | ||||
| 			skipped = append(skipped, k) | ||||
| 			continue | ||||
| 		} | ||||
| 		primary[k] = v | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func initPrimary(primary *spec.Swagger) { | ||||
| 	if primary.SecurityDefinitions == nil { | ||||
| 		primary.SecurityDefinitions = make(map[string]*spec.SecurityScheme) | ||||
| 	} | ||||
| 	if primary.Security == nil { | ||||
| 		primary.Security = make([]map[string][]string, 0, 10) | ||||
| 	} | ||||
| 	if primary.Produces == nil { | ||||
| 		primary.Produces = make([]string, 0, 10) | ||||
| 	} | ||||
| 	if primary.Consumes == nil { | ||||
| 		primary.Consumes = make([]string, 0, 10) | ||||
| 	} | ||||
| 	if primary.Tags == nil { | ||||
| 		primary.Tags = make([]spec.Tag, 0, 10) | ||||
| 	} | ||||
| 	if primary.Schemes == nil { | ||||
| 		primary.Schemes = make([]string, 0, 10) | ||||
| 	} | ||||
| 	if primary.Paths == nil { | ||||
| 		primary.Paths = &spec.Paths{Paths: make(map[string]spec.PathItem)} | ||||
| 	} | ||||
| 	if primary.Paths.Paths == nil { | ||||
| 		primary.Paths.Paths = make(map[string]spec.PathItem) | ||||
| 	} | ||||
| 	if primary.Definitions == nil { | ||||
| 		primary.Definitions = make(spec.Definitions) | ||||
| 	} | ||||
| 	if primary.Parameters == nil { | ||||
| 		primary.Parameters = make(map[string]spec.Parameter) | ||||
| 	} | ||||
| 	if primary.Responses == nil { | ||||
| 		primary.Responses = make(map[string]spec.Response) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										234
									
								
								vendor/github.com/go-openapi/analysis/schema.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										234
									
								
								vendor/github.com/go-openapi/analysis/schema.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,234 @@ | ||||
| package analysis | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/go-openapi/spec" | ||||
| 	"github.com/go-openapi/strfmt" | ||||
| ) | ||||
|  | ||||
| // SchemaOpts configures the schema analyzer | ||||
| type SchemaOpts struct { | ||||
| 	Schema   *spec.Schema | ||||
| 	Root     interface{} | ||||
| 	BasePath string | ||||
| 	_        struct{} | ||||
| } | ||||
|  | ||||
| // Schema analysis, will classify the schema according to known | ||||
| // patterns. | ||||
| func Schema(opts SchemaOpts) (*AnalyzedSchema, error) { | ||||
| 	if opts.Schema == nil { | ||||
| 		return nil, fmt.Errorf("no schema to analyze") | ||||
| 	} | ||||
|  | ||||
| 	a := &AnalyzedSchema{ | ||||
| 		schema:   opts.Schema, | ||||
| 		root:     opts.Root, | ||||
| 		basePath: opts.BasePath, | ||||
| 	} | ||||
|  | ||||
| 	a.initializeFlags() | ||||
| 	a.inferKnownType() | ||||
| 	a.inferEnum() | ||||
| 	a.inferBaseType() | ||||
|  | ||||
| 	if err := a.inferMap(); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if err := a.inferArray(); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	a.inferTuple() | ||||
|  | ||||
| 	if err := a.inferFromRef(); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	a.inferSimpleSchema() | ||||
| 	return a, nil | ||||
| } | ||||
|  | ||||
| // AnalyzedSchema indicates what the schema represents | ||||
| type AnalyzedSchema struct { | ||||
| 	schema   *spec.Schema | ||||
| 	root     interface{} | ||||
| 	basePath string | ||||
|  | ||||
| 	hasProps           bool | ||||
| 	hasAllOf           bool | ||||
| 	hasItems           bool | ||||
| 	hasAdditionalProps bool | ||||
| 	hasAdditionalItems bool | ||||
| 	hasRef             bool | ||||
|  | ||||
| 	IsKnownType      bool | ||||
| 	IsSimpleSchema   bool | ||||
| 	IsArray          bool | ||||
| 	IsSimpleArray    bool | ||||
| 	IsMap            bool | ||||
| 	IsSimpleMap      bool | ||||
| 	IsExtendedObject bool | ||||
| 	IsTuple          bool | ||||
| 	IsTupleWithExtra bool | ||||
| 	IsBaseType       bool | ||||
| 	IsEnum           bool | ||||
| } | ||||
|  | ||||
| // Inherits copies value fields from other onto this schema | ||||
| func (a *AnalyzedSchema) inherits(other *AnalyzedSchema) { | ||||
| 	if other == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	a.hasProps = other.hasProps | ||||
| 	a.hasAllOf = other.hasAllOf | ||||
| 	a.hasItems = other.hasItems | ||||
| 	a.hasAdditionalItems = other.hasAdditionalItems | ||||
| 	a.hasAdditionalProps = other.hasAdditionalProps | ||||
| 	a.hasRef = other.hasRef | ||||
|  | ||||
| 	a.IsKnownType = other.IsKnownType | ||||
| 	a.IsSimpleSchema = other.IsSimpleSchema | ||||
| 	a.IsArray = other.IsArray | ||||
| 	a.IsSimpleArray = other.IsSimpleArray | ||||
| 	a.IsMap = other.IsMap | ||||
| 	a.IsSimpleMap = other.IsSimpleMap | ||||
| 	a.IsExtendedObject = other.IsExtendedObject | ||||
| 	a.IsTuple = other.IsTuple | ||||
| 	a.IsTupleWithExtra = other.IsTupleWithExtra | ||||
| 	a.IsBaseType = other.IsBaseType | ||||
| 	a.IsEnum = other.IsEnum | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferFromRef() error { | ||||
| 	if a.hasRef { | ||||
| 		sch := new(spec.Schema) | ||||
| 		sch.Ref = a.schema.Ref | ||||
| 		err := spec.ExpandSchema(sch, a.root, nil) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		rsch, err := Schema(SchemaOpts{ | ||||
| 			Schema:   sch, | ||||
| 			Root:     a.root, | ||||
| 			BasePath: a.basePath, | ||||
| 		}) | ||||
| 		if err != nil { | ||||
| 			// NOTE(fredbi): currently the only cause for errors is | ||||
| 			// unresolved ref. Since spec.ExpandSchema() expands the | ||||
| 			// schema recursively, there is no chance to get there, | ||||
| 			// until we add more causes for error in this schema analysis. | ||||
| 			return err | ||||
| 		} | ||||
| 		a.inherits(rsch) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferSimpleSchema() { | ||||
| 	a.IsSimpleSchema = a.IsKnownType || a.IsSimpleArray || a.IsSimpleMap | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferKnownType() { | ||||
| 	tpe := a.schema.Type | ||||
| 	format := a.schema.Format | ||||
| 	a.IsKnownType = tpe.Contains("boolean") || | ||||
| 		tpe.Contains("integer") || | ||||
| 		tpe.Contains("number") || | ||||
| 		tpe.Contains("string") || | ||||
| 		(format != "" && strfmt.Default.ContainsName(format)) || | ||||
| 		(a.isObjectType() && !a.hasProps && !a.hasAllOf && !a.hasAdditionalProps && !a.hasAdditionalItems) | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferMap() error { | ||||
| 	if a.isObjectType() { | ||||
| 		hasExtra := a.hasProps || a.hasAllOf | ||||
| 		a.IsMap = a.hasAdditionalProps && !hasExtra | ||||
| 		a.IsExtendedObject = a.hasAdditionalProps && hasExtra | ||||
| 		if a.IsMap { | ||||
| 			if a.schema.AdditionalProperties.Schema != nil { | ||||
| 				msch, err := Schema(SchemaOpts{ | ||||
| 					Schema:   a.schema.AdditionalProperties.Schema, | ||||
| 					Root:     a.root, | ||||
| 					BasePath: a.basePath, | ||||
| 				}) | ||||
| 				if err != nil { | ||||
| 					return err | ||||
| 				} | ||||
| 				a.IsSimpleMap = msch.IsSimpleSchema | ||||
| 			} else if a.schema.AdditionalProperties.Allows { | ||||
| 				a.IsSimpleMap = true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferArray() error { | ||||
| 	// an array has Items defined as an object schema, otherwise we qualify this JSON array as a tuple | ||||
| 	// (yes, even if the Items array contains only one element). | ||||
| 	// arrays in JSON schema may be unrestricted (i.e no Items specified). | ||||
| 	// Note that arrays in Swagger MUST have Items. Nonetheless, we analyze unrestricted arrays. | ||||
| 	// | ||||
| 	// NOTE: the spec package misses the distinction between: | ||||
| 	// items: [] and items: {}, so we consider both arrays here. | ||||
| 	a.IsArray = a.isArrayType() && (a.schema.Items == nil || a.schema.Items.Schemas == nil) | ||||
| 	if a.IsArray && a.hasItems { | ||||
| 		if a.schema.Items.Schema != nil { | ||||
| 			itsch, err := Schema(SchemaOpts{ | ||||
| 				Schema:   a.schema.Items.Schema, | ||||
| 				Root:     a.root, | ||||
| 				BasePath: a.basePath, | ||||
| 			}) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 			a.IsSimpleArray = itsch.IsSimpleSchema | ||||
| 		} | ||||
| 	} | ||||
| 	if a.IsArray && !a.hasItems { | ||||
| 		a.IsSimpleArray = true | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferTuple() { | ||||
| 	tuple := a.hasItems && a.schema.Items.Schemas != nil | ||||
| 	a.IsTuple = tuple && !a.hasAdditionalItems | ||||
| 	a.IsTupleWithExtra = tuple && a.hasAdditionalItems | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferBaseType() { | ||||
| 	if a.isObjectType() { | ||||
| 		a.IsBaseType = a.schema.Discriminator != "" | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) inferEnum() { | ||||
| 	a.IsEnum = len(a.schema.Enum) > 0 | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) initializeFlags() { | ||||
| 	a.hasProps = len(a.schema.Properties) > 0 | ||||
| 	a.hasAllOf = len(a.schema.AllOf) > 0 | ||||
| 	a.hasRef = a.schema.Ref.String() != "" | ||||
|  | ||||
| 	a.hasItems = a.schema.Items != nil && | ||||
| 		(a.schema.Items.Schema != nil || len(a.schema.Items.Schemas) > 0) | ||||
|  | ||||
| 	a.hasAdditionalProps = a.schema.AdditionalProperties != nil && | ||||
| 		(a.schema.AdditionalProperties != nil || a.schema.AdditionalProperties.Allows) | ||||
|  | ||||
| 	a.hasAdditionalItems = a.schema.AdditionalItems != nil && | ||||
| 		(a.schema.AdditionalItems.Schema != nil || a.schema.AdditionalItems.Allows) | ||||
|  | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) isObjectType() bool { | ||||
| 	return !a.hasRef && (a.schema.Type == nil || a.schema.Type.Contains("") || a.schema.Type.Contains("object")) | ||||
| } | ||||
|  | ||||
| func (a *AnalyzedSchema) isArrayType() bool { | ||||
| 	return !a.hasRef && (a.schema.Type != nil && a.schema.Type.Contains("array")) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user