<commit_before>/*
    Copyright 2013, Strategic Gains, Inc.

	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 com.strategicgains.restexpress.plugin.swagger.domain;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.restexpress.domain.metadata.UriMetadata;
import org.restexpress.route.Route;

/**
 * @author toddf
 * @since Nov 21, 2013
 */
public class ApiOperation
extends DataType
{
	private String method;
	private String nickname = "";
	private List<ApiOperationParameters> parameters;
	private String summary = "";
	private String notes;
	private List<ApiResponse> errorResponses;

	public ApiOperation(Route route)
	{
		// TODO: use Swagger annotation on controller method, if present.
		// Get the method from the route
		Method m = route.getAction();
		if (m
		    .isAnnotationPresent(com.wordnik.swagger.annotations.ApiOperation.class))
		{
			com.wordnik.swagger.annotations.ApiOperation ao = m
			    .getAnnotation(com.wordnik.swagger.annotations.ApiOperation.class);
			// Both value and notes are used as descriptions in ApiOperation
			// annotation.
			// value is a brief description, notes a more detailed description.
			if (ao.value() != null) summary = ao.value();
			if (ao.notes() != null) notes = ao.notes();
		}

		this.method = route.getMethod().getName();
		String name = route.getName();
		this.nickname = method + (name == null ? "" : " " + name);

		if (route.getUrlParameters() == null) return;

		for (String param : route.getUrlParameters())
		{
			addParameter(new ApiOperationParameters("path", param, "string",
			    !param.equals("format")));
		}

		// TODO: determine body/input parameters.<commit_msg>Removed 'format' parameter from the ApiDeclaration since the swagger UI requires an entry even though it's marked as optional (and doesn't do appropriate substitution).<commit_after>/*
    Copyright 2013, Strategic Gains, Inc.

	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 com.strategicgains.restexpress.plugin.swagger.domain;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.restexpress.route.Route;

/**
 * @author toddf
 * @since Nov 21, 2013
 */
public class ApiOperation
extends DataType
{
	private String method;
	private String nickname = "";
	private List<ApiOperationParameters> parameters;
	private String summary = "";
	private String notes;
	private List<ApiResponse> errorResponses;

	public ApiOperation(Route route)
	{
		// TODO: use Swagger annotation on controller method, if present.
		// Get the method from the route
		Method m = route.getAction();
		if (m
		    .isAnnotationPresent(com.wordnik.swagger.annotations.ApiOperation.class))
		{
			com.wordnik.swagger.annotations.ApiOperation ao = m
			    .getAnnotation(com.wordnik.swagger.annotations.ApiOperation.class);
			// Both value and notes are used as descriptions in ApiOperation
			// annotation.
			// value is a brief description, notes a more detailed description.
			if (ao.value() != null) summary = ao.value();
			if (ao.notes() != null) notes = ao.notes();
		}

		this.method = route.getMethod().getName();
		String name = route.getName();
		this.nickname = method + (name == null ? "" : " " + name);

		if (route.getUrlParameters() == null) return;

		for (String param : route.getUrlParameters())
		{
			if (param.equals("format")) continue;

			addParameter(new ApiOperationParameters("path", param, "string", true));
		}

		// TODO: determine body/input parameters.
{'fraction_non_alphanumeric': 0.10260985946910552, 'fraction_numerical': 0.006245817532902075, 'mean_word_length': 4.010055865921788, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4765518', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1238, 'n_words': 445}