Improve safety and clarity in getProducer to handle unnamed response properties#971
Merged
marina-p merged 1 commit intomicrosoft:mainfrom Aug 21, 2025
landoncrabtree:landoncrabtree-patch-1
Merged
Improve safety and clarity in getProducer to handle unnamed response properties#971marina-p merged 1 commit intomicrosoft:mainfrom landoncrabtree:landoncrabtree-patch-1
marina-p merged 1 commit intomicrosoft:mainfrom
landoncrabtree:landoncrabtree-patch-1
Conversation
…properties This change refactors the `getProducer` function to improve safety and maintainability: Ensures name.Value is only accessed after confirming name.IsSome, preventing potential NullReferenceExceptions when response properties are unnamed. Improves DEBUG logging to provide clearer diagnostics when unnamed properties are encountered. These improvements reduce the chance of runtime errors when parsing Swagger specs with unnamed or array-based responses and make future debugging and maintenance easier.
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Contributor
|
Thank you for the improvements! In reply to: 3138655697 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If response entries in a Swagger spec are arrays (and not objects), then when attempting to compile via
Restler compile --api_spec, it will throw an error:With the following error logs,
Here is a simple Swagger spec to reproduce the issue:
{ "swagger": "2.0", "info": { "version": "1.0.0", "title": "PoC API" }, "paths": { "/api/do-something": { "get": { "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "type": "array", "items": { "type": "string" } } } } } } } } }The proposed changes add better safety handling in the case there is no top-level object (e.g. nested arrays), where
.namecould be null. This preventsNullReferenceException, however, it still does not implement the actual producer logic:TODO: support cases where the entire response is an array